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

cloneDeep breaking change #4090

Closed
KamalAman opened this issue Nov 2, 2018 · 1 comment
Closed

cloneDeep breaking change #4090

KamalAman opened this issue Nov 2, 2018 · 1 comment

Comments

@KamalAman
Copy link

Intended outcome:
Unchanged objects should not be modified when caching lastResults, and Symbols should be preserved with cloneDeep .

Version 2.4.3 supported copying symbols to new objects while 2.4.4 does not
This PR introduced the bug: #4052

While the effects of this bug being introduced seemed resolved by #4069 in 2.4.5 due to the cloned object only being used by lastResultSnapshot for isDifferentFromLastResult,the underlying bug still exists.

Furthermore, there is no reason to deep clone objects. Objects should be immutable, shallow copy object when modifying them. It seems like the strategy in this PR #4089

Actual outcome:
Object symbols are not copied over

How to reproduce the issue:

let obj = {};
obj[Symbol('a')] = 'a';

let clonedObject = cloneDeep(obj);

expect(clonedObject[Symbol('a')]).to.equal('a')

Versions
Introduced in apollo-client 2.4.4
Side-effects resolved in apollo-client 2.4.5, however bug still technically exists

@benjamn
Copy link
Member

benjamn commented Nov 2, 2018

Symbol properties were not copied by the previous fclone implementation in [email protected] (i.e. [email protected]) and earlier, so this is only a breaking change with respect to a very temporary implementation that was found to be prohibitively slow, as discussed in #4039. In some sense, the act of copying symbols was a breaking change that we have now undone.

Furthermore, there is no reason to deep clone objects. Objects should be immutable, shallow copy object when modifying them.

That's a nice aspiration that you are welcome to pursue in your own code, but as the maintainers of a library written in a language that does not enforce immutability in the type system, it's important to appreciate that any object exposed to application code can and will be modified by someone.

I'm not interested in bugs that only technically exist. Everyone else is here to get help building real applications. Feel free to reopen this issue when you have an actual use case to discuss.

@benjamn benjamn closed this as completed Nov 2, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants