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,20 +136,28 @@ export function hydrate(component, options) {
return /** @type {Exports} */ (instance); return /** @type {Exports} */ (instance);
} catch (error) { } catch (error) {
if (error === HYDRATION_ERROR) { // re-throw Svelte errors - they are certainly not related to hydration
if (options.recover === false) { if (
e.hydration_failed(); error instanceof Error &&
} error.message.split('\n').some((line) => line.startsWith('https://svelte.dev/e/'))
) {
// If an error occured above, the operations might not yet have been initialised. throw error;
init_operations(); }
clear_text_content(target); if (error !== HYDRATION_ERROR) {
// eslint-disable-next-line no-console
console.warn('Failed to hydrate: ', error);
}
set_hydrating(false); if (options.recover === false) {
return mount(component, options); 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 { } finally {
set_hydrating(was_hydrating); set_hydrating(was_hydrating);
set_hydrate_node(previous_hydrate_node); 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