-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Prevent effect_update_depth_exceeded when using bind:value on a select with deriveds state in legacy components #16165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Prevent effect_update_depth_exceeded when using bind:value on a select with deriveds state in legacy components #16165
Conversation
🦋 Changeset detectedLatest commit: 0ceac96 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…s from <select> bind:value on $: derived variables
…s from <select> bind:value on $: (block) with derived variable
ec44f01
to
0ceac96
Compare
|
I wonder why function select_change_handler() {
details.country = select_value(this);
($$invalidate(0, details), $$invalidate(1, data));
} |
Mmh interesting, I can try to change my solution to do that and see if it works ^^. So to mimic the svelte 4 behavior we should call it inside the mutate callback of the value binding right? |
|
Fixes #13768
The bug
In legacy mode Svelte generates extra code for every
<select bind:value={…}>
.That helper reads the bound value and immediately calls
invalidate_inner_signals
, which writes back to the signals it justread so that indirect updates propagate.
When the bound value itself is produced by a reactive statement
(
$:
) this write-back creates a tight loop:details.country
invalidate_inner_signals
doesinternal_set(data, data)
$:
re-runs, re-assignsdetails
runtime throws
effect_update_depth_exceeded
.What this PR does
Stops emitting the helper when it’s not needed.
In
setup_select_synchronization
we now check the bound identifier:If either condition is true the synchronisation helper is omitted,
breaking the cycle. For all other bindings (plain state, props,
store-subs, etc.) the helper is still generated, so existing behaviour should be
unchanged.
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint