mirror of https://github.com/sveltejs/svelte
fix: better error messages for invalid HTML trees (#14445)
* fix: better error messages for invalid HTML trees closes #13331 * fix test * more concise * tweak * tweak messages * adjust tests * tweak message slightly, so it doesn't sound like the bad element is the one we're currently encountering * put locations in generated message * tidy up * consistency * fix --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/14548/head
parent
4e77bdef74
commit
86ae349bcc
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: better error messages for invalid HTML trees
|
@ -0,0 +1,21 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
|
||||||
|
html: `<form><div></div></form>`,
|
||||||
|
|
||||||
|
recover: true,
|
||||||
|
|
||||||
|
mode: ['hydrate'],
|
||||||
|
|
||||||
|
errors: [
|
||||||
|
'node_invalid_placement_ssr: `<form>` (form.svelte:1:0) cannot be a descendant of `<form>` (main.svelte:5:0)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.'
|
||||||
|
],
|
||||||
|
|
||||||
|
warnings: [
|
||||||
|
'Hydration failed because the initial UI does not match what was rendered on the server'
|
||||||
|
]
|
||||||
|
});
|
@ -0,0 +1 @@
|
|||||||
|
<form></form>
|
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
import Form from './form.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<div>
|
||||||
|
<Form />
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -1 +1 @@
|
|||||||
<script>console.error("node_invalid_placement_ssr: `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:1:0) cannot contain `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.")</script>
|
<script>console.error("node_invalid_placement_ssr: `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1) cannot be a child of `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:1:0)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.")</script>
|
||||||
|
Loading…
Reference in new issue