S
SolidJS13mo ago
Driver

Bug with `solid-js/store` and `solid-primitives/history`

I ran into a bug and reproduced it in this stackblitz. For some reason with this configuration of the store object like this: { [key: number]: { image: { id: number } | undefined; } } the history object is starting to resurrect it incorrectly, like skipping the state (see in the video) My guess is that the reconcile function is not working correctly, but I could be wrong https://stackblitz.com/edit/solidjs-templates-jzapxh?file=src%2Ftest-todo.comopnent.tsx
4 Replies
Driver
Driver13mo ago
Digging deeper, it seems that the problem is in structuredClone function No, it's exactly a problem in the reconcile function.
Driver
Driver13mo ago
Okay, I don't get it at all now. It's acting really weird in general. https://stackblitz.com/edit/solidjs-templates-88j7ru?file=src%2Ftest-todo.comopnent.tsx
Driver
Driver12mo ago
I am now 100% sure that the bug is in the reconcile function. I was able to reproduce it here: https://stackblitz.com/edit/typescript-fcz5m5?file=index.ts
SonyStone
StackBlitz
solid-js/store reconcile bug - StackBlitz
Blank starter project for building TypeScript apps.
thetarnav
thetarnav12mo ago
reconcile is always hard to follow, but I think the reason is that you reset the result to an empty object by doing reconcile(start)(result). if result is {} the next reconcile has to reuse the whole object to fill the 0 property, so if you do reconcile(first) and reconcile(second), 0 will be assigned from first, and then that will be merged with second and the object mutated. I think the general design with stores is that they mutate the source, so you need to clone the assigned object every time you assign it if you want to keep it untouched. Although that is a bit annoying when doing undo history I guess. if you need to copy when storing and copy when reconciling. One could definitely write a smarter reconcile that clones the assigned objects, if that would be worth it.
Want results from more Discord servers?
Add your server