mirror of https://github.com/sveltejs/svelte
fix: ensure hydration state restoration for custom element attribute updates (#18467)
### Problem While hydrating custom elements, set_attributes temporarily disables global hydration state via set_hydrating(false) and restores it only at the end. If a prop setter or attribute operation throws partway through, hydration mode can remain disabled globally. ### Fix Wrap the temporary hydration-state override in a try/finally block in set_attributes so set_hydrating(true) always runs when is_hydrating_custom_element is true. --------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>main
parent
28b99aa8e6
commit
020242d6be
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: restore hydration state when custom element attribute updates throw
|
||||
@ -0,0 +1,11 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['hydrate'],
|
||||
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, '<p>failed: setter error</p><p>after</p>');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
<script module>
|
||||
if (!customElements.get('throwing-element')) {
|
||||
customElements.define(
|
||||
'throwing-element',
|
||||
class extends HTMLElement {
|
||||
set value(_) {
|
||||
throw new Error('setter error');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:boundary>
|
||||
<throwing-element {...{ value: 'boom' }}></throwing-element>
|
||||
|
||||
{#snippet failed(error)}
|
||||
<p>failed: {error.message}</p>
|
||||
{/snippet}
|
||||
</svelte:boundary>
|
||||
|
||||
<p>after</p>
|
||||
Loading…
Reference in new issue