-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the bug
I remember Svelte having this issue before but now I noticed it's back.
When a component has spread props from a derived object, or perhaps any state that its reference changes entirely; It can cause the bindable props that have the default value of undefined, to go back to undefined.
Reproduction
For example here we have a simple Test component that does nothing special other than inspecting the bindable prop.
Test.svelte
<script lang="ts">
let { ref = $bindable(), ...restProps } = $props();
$inspect(ref);
</script>
<div bind:this={ref} {...restProps}></div>
And then in our page we pass it a spread props object that is derived, for example
+page.svelte
<script lang="ts">
import Test from "$components/Test/Test.svelte";
let hovered = $state(false);
const spreadProps = $derived({
hovered
});
</script>
<Test {...spreadProps}></Test>
<button
onmouseenter={() => {
hovered = true;
}}
onmouseleave={() => {
hovered = false;
}}>button</button
>
After hovering over the button, you will notice that the $inspect inside Test.svelte will indicate that ref is changed to undefined.
Here's a REPO
For some reason the repo's console can't show the output of the $inspect properly so open your browser's devtools instead to see the log.
Logs
System Info
System:
OS: Windows 11 10.0.22631
CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
Memory: 6.50 GB / 15.63 GB
Binaries:
Node: 23.7.0 - C:\Program Files\nodejs\node.EXE
npm: 11.1.0 - C:\Program Files\nodejs\npm.CMD
bun: 1.1.3 - ~\.bun\bin\bun.EXE
Browsers:
Edge: Chromium (129.0.2792.52)
Internet Explorer: 11.0.22621.3527
Severity
blocking all usage of svelte