mirror of https://github.com/sveltejs/svelte
feat: improve ssr html mismatch validation (#10658)
* feat: improve ssr html mismatch validation * update types * Update packages/svelte/src/internal/server/index.js Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * Update packages/svelte/src/compiler/validate-options.js Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * feedback --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>pull/10661/head
parent
3fe4940a9d
commit
99e1665ce1
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: improve ssr html mismatch validation
|
@ -0,0 +1 @@
|
|||||||
|
<h1>foo</h1>
|
@ -0,0 +1,41 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
let console_error = console.error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {any[]}
|
||||||
|
*/
|
||||||
|
const log = [];
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
|
||||||
|
html: `<p></p><h1>foo</h1><p></p>`,
|
||||||
|
|
||||||
|
recover: true,
|
||||||
|
|
||||||
|
before_test() {
|
||||||
|
console.error = (x) => {
|
||||||
|
log.push(x);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
after_test() {
|
||||||
|
console.error = console_error;
|
||||||
|
log.length = 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target, variant }) {
|
||||||
|
await assert.htmlEqual(target.innerHTML, `<p></p><h1>foo</h1><p></p>`);
|
||||||
|
if (variant === 'hydrate') {
|
||||||
|
assert.equal(
|
||||||
|
log[0],
|
||||||
|
`Svelte SSR validation error:\n\n<h1> is invalid inside <p>\n\n` +
|
||||||
|
'Ensure your components render valid HTML as the browser will try to repair invalid HTML, ' +
|
||||||
|
'which may result in content being shifted around and will likely result in a hydration mismatch.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
import Component from "./Component.svelte";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<Component />
|
||||||
|
</p>
|
Loading…
Reference in new issue