-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Radio button group only renders correctly when using keyed #each #4207
Comments
This is the behaviour I would expect from an un-keyed array in this scenario. I'm not sure how feasible it would be to auto-detect the need for a keyed each, or if it is even desirable, so this is more of a docs thing. The issue is I'm not even sure how we could document this without it being TMI for most users. The concept around keying is already documented. I'll have a look at docs for keying features on similar projects and see if there are any improvements to make. |
It seems like keyed each blocks should be used whenever possible then? Ideally svelte would warn though when in dev mode if it isn't going to be able to render the each body correctly. I've run into a few scenarios where each bodies aren't updated correctly. For instance, this issue shows one where it's in a slot: #4165. If a keyed each is used, it works, else it renders the incorrect image. |
fwiw, I also noticed it renders correctly if I fully reset the value that the each loop is using:
|
@JohnnyFun that also makes sense. The keying is designed to track elements, so rewriting the entire list will create new tracking keys internally, and thus render correctly. The other ticket has been marked as a bug by @Conduitry but I'm not sure that this is the same issue. |
@antony, yeah I don't think they're the exact same issue, but what seems similar between the two is that svelte mostly updates the UI, but doesn't quite get everything. I also noticed if I use the object ref as the key in a keyed each, it works correctly (i.e. Another thing I noticed that makes it render correctly is:
I've been able to work around these not-quite-updated-UI scenarios by doing Here's hoping the fix for the other one either fixes this one too, or shakes something loose that makes it clear why this kind of thing can happen or how svelte might warn about it in dev mode. |
even if the search box is cleared you will get |
Tested this issue with the REPL: https://svelte.dev/repl/f40fe70abc134108bfe125fa111254ea?version=3.16.7 from @JohnnyFun (before changing the #each line) |
Closing as stale / likely fixed |
Describe the bug
If a radio input group is setup with a filter, the radio button doesn't show as selected upon filtering, unless a keyed
{#each}
is used. See REPL for example: https://svelte.dev/repl/f40fe70abc134108bfe125fa111254ea?version=3.16.7Expected behavior
Upon filtering "bob", "bobby" should be selected.
Or svelte could warn about these scenarios, if possible, and instruct to use a keyed each. And svelte could fallback to re-rendering entire each block or something so that it at least gets rendered correctly. But not sure on internals...so.
Information about your Svelte project:
Chrome Version 79.0.3945.88 (Official Build) (64-bit)
Your operating system: Win10
Svelte version: 3.16.7
The text was updated successfully, but these errors were encountered: