Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-eagles-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: remount at any hydration error
27 changes: 16 additions & 11 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,25 @@

return /** @type {Exports} */ (instance);
} catch (error) {
if (error === HYDRATION_ERROR) {
if (options.recover === false) {
e.hydration_failed();
}

// If an error occured above, the operations might not yet have been initialised.
init_operations();
clear_text_content(target);
// re-throw Svelte errors - they are certainly not related to hydration
if (error instanceof Error && error.message.includes('https://svelte.dev/e/')) {
throw error;
}
if (error !== HYDRATION_ERROR) {
// eslint-disable-next-line no-console
console.warn('Failed to hydrate: ', error);
}

set_hydrating(false);
return mount(component, options);
if (options.recover === false) {
e.hydration_failed();
}

throw error;
// If an error occured above, the operations might not yet have been initialised.
init_operations();
clear_text_content(target);

set_hydrating(false);
return mount(component, options);
} finally {
set_hydrating(was_hydrating);
set_hydrate_node(previous_hydrate_node);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>nested</p>
Original file line number Diff line number Diff line change
@@ -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')
]
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<main><p>nested</p><!----></main>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!--[-->
<main><p>nested</p><!----></main><!--]-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import Nested from './Nested.svelte';
</script>

<main>
<Nested />
</main>