solid-record icon indicating copy to clipboard operation
solid-record copied to clipboard

Undo fails at reverting additions to a store object

Open ThaisRobba opened this issue 2 years ago • 2 comments

When using a store with objects and adding new key value pairs, undo (and probably redo) don’t quite work. Oddly enough it works fine if it is used with object signals

Example to reproduce:

const [data, setData, history] = record(createStore({}));

setData({ hello: true }) // This will be pushed to record history

history.undo() // This will move the undo index backwards but not revert the last setData

return <h1>{data.hello.toString()}</h1> // true

ThaisRobba avatar May 22 '23 01:05 ThaisRobba

Nested objects in a store also fail. Probably something to do with how store objects are proxies?

Nested objects in a signals work fine so that might be it.

ThaisRobba avatar May 22 '23 01:05 ThaisRobba

Hey @ThaisRobba, thanks for reporting! The issue is that solidjs shallowly merges object properties when you provide an object to a store setter. So basically in your example undoing the change would be the same as simply calling setStore({}), which wouldn't do anything either since {} would be merged with { hello: true }. Simply wrapping the object in reconcile() should resolve the issue.

I will fix this asap, thanks again!

mountfx avatar May 22 '23 11:05 mountfx