Logic vs intuition on list indexes and rerenders in For loops #399
-
From Discord chat: So I encountered some behaviour recently that is not intuitive for me (though it is logically correct). I've put it into a little example: https://playground.solidjs.com/?hash=417467847 Essentially I have a list that uses the Which is understandable. But at the same time is confusing because naively it feels like Solid should have been passing a changed The fix is simple, just force the re-run by adding a dependency (unused) on I thought it an interesting case and when raised in Discord there was some agreement that this might be a good example for the 1.0 docs. I'll probably write a short blog post about this, so would be happy to contribute to docs as well if there is interest? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Solid typically does referential checks. And with its internals relying on mutation this works fine. When you replace an item or remove it referential checks will remove and place new item if applicable. Solid is even more optimized than that though. If you change properties on an object in an array the array doesn't update. We know that it is conceptually the same so no need to reconcile. Under normal situations like typical mutation of array or nested object this will always work. But that's the thing It's arguable if merge option isn't and it fails to find key we should always recreate everything though, but I thought fallback to "key by index" was better. That being said maybe there is something else weird going on. Since I would think this wouldn't be a problem. I will investigate more. |
Beta Was this translation helpful? Give feedback.
Solid typically does referential checks. And with its internals relying on mutation this works fine. When you replace an item or remove it referential checks will remove and place new item if applicable. Solid is even more optimized than that though. If you change properties on an object in an array the array doesn't update. We know that it is conceptually the same so no need to reconcile. Under normal situations like typical mutation of array or nested object this will always work.
But that's the thing
reconcile
can only do so much with deep cloned data. If it is structurally cloned like redux it will attempt to keep references. Failing that it will look for a key property. Default isid
…