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

Unexpected store invalidation inside each block / select tag #5818

Closed
vkurko opened this issue Dec 23, 2020 · 6 comments
Closed

Unexpected store invalidation inside each block / select tag #5818

vkurko opened this issue Dec 23, 2020 · 6 comments

Comments

@vkurko
Copy link

vkurko commented Dec 23, 2020

Describe the bug
If you put an array inside a store, then assign an item from that array to a variable and use both in select tag (or very likely in any similar each block) then you will unexpectedly get the store invalidated even though it was not modified during the loop. This causes side-effects which break the functionality (see REPL link below).

To Reproduce
Please see the issue at https://svelte.dev/repl/b08ad3a4aa334e37837769efd3e64e4a?version=3

The first select works fine and allows you to choose any of 2 options.
The second select does not allow you to choose another option. It is stuck on "item 2".

Expected behavior
Both selects allow to choose any options.

Additional context
Svelte version 3.31.0

@vkurko
Copy link
Author

vkurko commented Dec 24, 2020

Probably the issue was introduced by these changes #2444.

@tanhauhau
Copy link
Member

You are not supposed to bind:value which is reactively declared:

<script>
    $: selectedItem2 = $items2[selectedIdx];
</script>

<select bind:value={selectedItem2} />

which leads to unexpected behavior.

see #4933

@vkurko
Copy link
Author

vkurko commented Dec 29, 2020

Isn't selectedItem1 reactively declared too? It works fine in my example.

I'm not sure which condition from #4933 my case applies to. But it seems to be related.

@Phaqui
Copy link
Contributor

Phaqui commented Dec 31, 2020

Yes, you are correct, vkurko. I almost broke my head trying to figure out what is actually going on in your example. Of course, the fix is simple: Just have the variables be normal variables defined by let (they are not really reactive). But why exactly the first example seems to work, and the other one doesn't? I have no idea.

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 27, 2021
@dummdidumm
Copy link
Member

Closing as duplicate of #4933 which is the more general issue about this topic

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

No branches or pull requests

5 participants