svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Bound constants are `null` in `onDestroy`

Open sockmaster27 opened this issue 1 year ago • 1 comments

Describe the bug

When a parent does bind:x on a child's export const x and attempts to use this value in the onDestroy callback, the value of x is null. This is a breaking change while using Svelte 4 syntax, since x would previously keep the same value.

Reproduction

https://svelte.dev/playground/e7886cdc76d14523bec2b84ea5ace46f?version=5.1.0

Logs

No response

System Info

Not relevant

Severity

blocking an upgrade

sockmaster27 avatar Oct 24 '24 15:10 sockmaster27

I think this is one of those cases where need to document the differences to Svelte 4. In Svelte 5, the signal and effect architecture works quite differently to the top-down component rendering of Svelte 4. As such, I don't think there's anything we can do here.

trueadm avatar Oct 24 '24 20:10 trueadm

I found that with Svelte 5, when onDestroy() was called, the current page was no longer available. When using SvelteKit, the next page is loaded and the new page is available in the onDestroy() function of document.documentElement. Migration guide might help.

patoi avatar Jan 13 '25 13:01 patoi