Skip to content
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

2-way value binding on multiple select causes effect_update_depth_exceeded #724

Open
AlexJMohr opened this issue Feb 12, 2025 · 0 comments

Comments

@AlexJMohr
Copy link

I want to wrap svelte-select in a custom component MySelect, where the value is just value, not the list of full selected objects. It should be a full 2-way binding, i.e. modifying the value outside of MySelect should work, but I can't figure out how without causing the error effect_update_depth_exceeded

REPL: https://svelte.dev/playground/d6bf0339969e40a181352d3aaaee5f3a?version=5.19.10

// keep value in sync with selection
let selection = $state(value);
$effect(() => {
  value = selection?.map(i => i.value)
})
// keep selection in sync with value (from external changes)
// FIXME: causes effect loop
$effect(() => {
  selection = value;
})

// bind:value={selection}

I also tried using justValue, but it's the same result:

// keep value in sync with selection
let selection = $state(value);
let justValue = $state();
$effect(() => {
  value = justValue;
})
// keep selection in sync with value (from external changes)
// FIXME: causes effect loop
$effect(() => {
  selection = value;
})

// bind:value={selection} bind:justValue

I've seen a few other issues on here asking for justValue to be read/write, which I think would also solve my problem.

Any other suggestions? Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant