fix: remount at any hydration error (#16248)

* fix: remount at any hydration error

* re-throw svelte error immediately

* log error as warn

* fix?
pull/16566/head
7nik 1 month ago committed by GitHub
parent d8c3f3d87e
commit bbd0b1ed87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: remount at any hydration error

@ -136,7 +136,18 @@ export function hydrate(component, options) {
return /** @type {Exports} */ (instance);
} catch (error) {
if (error === HYDRATION_ERROR) {
// re-throw Svelte errors - they are certainly not related to hydration
if (
error instanceof Error &&
error.message.split('\n').some((line) => line.startsWith('https://svelte.dev/e/'))
) {
throw error;
}
if (error !== HYDRATION_ERROR) {
// eslint-disable-next-line no-console
console.warn('Failed to hydrate: ', error);
}
if (options.recover === false) {
e.hydration_failed();
}
@ -147,9 +158,6 @@ export function hydrate(component, options) {
set_hydrating(false);
return mount(component, options);
}
throw error;
} finally {
set_hydrating(was_hydrating);
set_hydrate_node(previous_hydrate_node);

@ -0,0 +1,8 @@
import { test } from '../../test';
export default test({
errors: [
'Failed to hydrate: ',
new DOMException("Node can't be inserted in a #text parent.", 'HierarchyRequestError')
]
});

@ -0,0 +1,2 @@
<!--[-->
<main><p>nested</p><!----></main><!--]-->

@ -0,0 +1,7 @@
<script>
import Nested from './Nested.svelte';
</script>
<main>
<Nested />
</main>
Loading…
Cancel
Save