Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

GoldingAustin
Copy link
Contributor

@GoldingAustin GoldingAustin commented Oct 10, 2024

Fix new array index value not being cloned before insertion into store - Fixes #5099

Additions to test cases:

Copy link

changeset-bot bot commented Oct 10, 2024

🦋 Changeset detected

Latest commit: 3ff295d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@xstate/solid Patch

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

// Update new or now undefined indexes
if (newIndices !== 0) {
for (let newEnd = smallestSize; newEnd <= largestSize - 1; newEnd++) {
set(...path, newEnd, deepClone(next[newEnd]));
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

@GoldingAustin GoldingAustin Oct 16, 2024

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

Copy link
Member

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 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: useActor from @xstate/solid mutates context
2 participants