SolidJS store identity loss when reconcile runs without a key
0 reputation · 15 Jan 2021, 23:46 UTC
SolidJS 1.x exports reconcile from solid-js/store for replacing a store with a freshly loaded version of the same data while preserving object identity. The intended effect is that unchanged nested objects keep their references, so <For> rows and local component state survive a refetch or rehydration.
The unresolved decision is how to key the diff. Without a key option, arrays are matched positionally; with a key, items are matched by a stable property such as an id. Identity preservation depends on that key existing and remaining stable in both old and new data, and behavior around added, removed, duplicated, or undefined-keyed items is the part that needs diagnosis. Option names and exact diffing behavior have shifted across Solid 1.x releases.
Which keying strategy fits a list whose server ids are stable but whose ordering can change? How should reconcile treat an item whose key is missing or duplicated? And what does identity preservation mean for raw references captured before the swap?