Description
Describe the bug
This issue happens in Svelte 5 (both legacy and runes mode), but does not happen in Svelte 4.
Expected logs after clicking the Reset value
button in the minimal example REPL:
on destroy
{ name: "John" }
Actual logs (Svelte 5):
on destroy
undefined
Note the TypeScript type shows the prop cannot be undefined.
Even though this would be a feature, it is quite inconvenient that the TypeScript type lies here. I was confused about this during a migration from Svelte 4 after I got a TypeError
in runtime JS after accessing an attribute of a prop object that was actually undefined. I tried also the legacy mode, runes/stores and it is everytime the same behaviour in Svelte 5.
Note that in Svelte 4 the output is correct - i.e. the prop is defined even in the onDestroy callback.
Reproduction
https://svelte.dev/playground/dc576c8a0dd94ff095ddb9a6976cfeaa?version=5.14.0
Logs
No response
System Info
System:
OS: Windows 11 10.0.26100
CPU: (16) x64 AMD Ryzen 7 PRO 6850U with Radeon Graphics
Memory: 1.82 GB / 14.76 GB
Binaries:
Node: 22.9.0 - ~\AppData\Local\fnm_multishells\28452_1734370019306\node.EXE
Yarn: 1.22.22 - ~\AppData\Local\fnm_multishells\28452_1734370019306\yarn.CMD
npm: 10.9.0 - ~\AppData\Local\fnm_multishells\28452_1734370019306\npm.CMD
Browsers:
Edge: Chromium (131.0.2903.99)
Internet Explorer: 11.0.26100.1882
Severity
annoyance