-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[@xstate/solid] Fix context mutation with new values nested in arrays #5100
base: main
Are you sure you want to change the base?
[@xstate/solid] Fix context mutation with new values nested in arrays #5100
Conversation
…tion into store - Fix statelyai#5099 Signed-off-by: Austin Golding <[email protected]>
🦋 Changeset detectedLatest commit: 3ff295d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…tion into store - Fix statelyai#5099 Signed-off-by: Austin Golding <[email protected]>
// Update new or now undefined indexes | ||
if (newIndices !== 0) { | ||
for (let newEnd = smallestSize; newEnd <= largestSize - 1; newEnd++) { | ||
set(...path, newEnd, deepClone(next[newEnd])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought we might only have to deep clone everything once upfront - do we deep clone objects anywhere else while performing other types of updates right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps my question is - wow is this handled when a new property is being added to an object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my initial testing, only inserting into an array seems to require a deep clone. With objects, we're able to diff down to primitives, but with a new index in an array, it doesn't update properly unless we insert the full value. Maybe there's a way we can modify array updates to work the same way objects are updated, but that'll take more research/testing. Moving nested objects around and into new properties works as expected.
I will dig deeper into this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Austin. I appreciate it ❤️
Fix new array index value not being cloned before insertion into store - Fixes #5099
packages/xstate-solid/src/createImmutable.ts
: Refactored theupdateStore
function to deep clone new elements in the array, ensuring immutability.Additions to test cases:
packages/xstate-solid/test/useActor.test.tsx
: Added a new test case to verify that moving objects between arrays does not mutate the context.