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

Fixed incorrect changed path when mutating unrelated area of proxy during iteration operations on cloned areas of the proxy. #105

Merged

Conversation

brendon1982
Copy link
Contributor

Hi,

I've been using your fantastic library in a side project, and I picked up an edge case that occurs when iterating over some part of the proxy and during that iteration modify a different part of the proxy. In this case the change path reported as the property currently being iterated over instead of the mutated property.

For example, if I have this object:

{
  a: [
    {
    quantity: 1
    }
  ],
  b: {
    c: {
      quantity: 8,
    },
  }
};

And I do the following:

proxy.a.forEach(() => {
  proxy.b.c = {
    quantity: 3,
  };
});

The expected change path is b.c, however, it is reported as a.

The issue seems to be that the handleChange would detect that a SmartClone is active, due to the forEach, and therefore branch into the logic for updating the clone without first checking if the change path applies to the clone.

@brendon1982
Copy link
Contributor Author

Hi,

It seems like I failed pretty hard on the eslint side and have had to make additional commits to address the issues.

Would you prefer that I make a new pull request with everything squashed?

@sindresorhus
Copy link
Owner

Would you prefer that I make a new pull request with everything squashed?

No. I will squash on merge.

lib/path.js Outdated Show resolved Hide resolved
@sindresorhus sindresorhus merged commit 283bc26 into sindresorhus:main Jan 14, 2024
2 checks passed
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.

2 participants