You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a spread property and also binding to an array value on the spread object causes an infinite update cycle. This only seems to happen if the bound value is an array or an object.
<script>
importComponent2from'./Component2.svelte';let values = [{ x:5, y: [6] }];
</script>
<!-- Uncomment the below to trigger the bug --><!-- <Component2 {...value} bind:y={value.y} /> -->
Expected behavior
Catch at compile time if possible. Not sure how feasible that is due to possible aliasing?
Regardless, some way to avoid crashing the page would be good. Maybe remove the key related to the bound variable from the changes object when spreads and binds are being used.
Information about your Svelte project:
REPL with latest Svelte
Severity
Not my bug, saw it mentioned in the Discord. Since there's a non-spread workaround I assume not a blocker but I'll let the original reporter chime in if it is.
Analysis
Looking in the generated code, we see in the bind handler below that it takes care to not add y to component2_changes if updating_y is true.. But get_spread_update returns both x and y regardless of the value of updating_y, so I believe this is what leads to the infinite updates.
In the meantime, if other people run into this, here's one workaround I've found using reduce to manually remove any bound props from the spread. This is assuming there's a need to use the spread operator in order to honor default component values for unspecified props. Of course, ideally there'd be no way to crash the page like this, but this works!
Describe the bug
Using a spread property and also binding to an array value on the spread object causes an infinite update cycle. This only seems to happen if the bound value is an array or an object.
To Reproduce
REPL: https://svelte.dev/repl/a0b9cf113353432b9242e78099ac8fd8?version=3.24.0
Expected behavior
Catch at compile time if possible. Not sure how feasible that is due to possible aliasing?
Regardless, some way to avoid crashing the page would be good. Maybe remove the key related to the bound variable from the changes object when spreads and binds are being used.
Information about your Svelte project:
REPL with latest Svelte
Severity
Not my bug, saw it mentioned in the Discord. Since there's a non-spread workaround I assume not a blocker but I'll let the original reporter chime in if it is.
Analysis
Looking in the generated code, we see in the bind handler below that it takes care to not add
y
tocomponent2_changes
ifupdating_y
is true.. Butget_spread_update
returns bothx
andy
regardless of the value ofupdating_y
, so I believe this is what leads to the infinite updates.I wonder if adding something like this at the end would fix it:
The text was updated successfully, but these errors were encountered: