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

refactor to use lodash.isEqual instead of custom isEqual #4903

Closed
wants to merge 1 commit into from

Conversation

capaj
Copy link
Contributor

@capaj capaj commented Jun 1, 2019

I was trying out a hermes cache and ran into this issue: convoyinc/apollo-cache-hermes#414

now in order to solve this issue I think the best option is to support comparing cyclic objects in isEqual. Current custom implementation does not support them and runs into an infinite recursion.
Thankfully lodash does support cyclic objects just fine and since it does mirror the behaviors of the current custom isEqual, I hope it could be used instead. lodash.isequal package is already required by react-apollo so people using apollo-client in react won't see any bundle size change.

The only other way of resolving the hermes cache issue I see could be to offer a way to let a cache override the isDifferentFromLastResult implementation, but since isEqual is in the util package, IMHO it would be only a matter of time when someone would run into this problem in the future when reusing the isEqual on other places in apollo monorepo.

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

I also inadvertently made some formatting changes as I saved the files. Hope that it's okay-it's just some formatting.

NOTE that apollo-utilities package will need to be bumped by a major as I have removed the util function from the package.

@META-DREAMER
Copy link
Contributor

Related issue: #4824

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding the dependency to apollo-cache-inmemory and apollo-client, let's just reimplement the apollo-utilities version of isEqual using lodash.isequal.

@capaj
Copy link
Contributor Author

capaj commented Jun 4, 2019

@benjamn so the tests for isEqual in this repo will be testing already very well tested lodash implementation? Seems a like someone needs a tin foil 🤠. You don't think @jdalton's implementation passes your small suite of tests? Well it does. That was the first thing I've tried.
I don't think it's necessary to test your dependecies-that's what semver is for. Anyways I will leave this PR open just in case you change your mind. I will open the one you requested as another one and you can decide which one you like better.

@capaj
Copy link
Contributor Author

capaj commented Jun 4, 2019

opened an alternative fix PR here: #4915
I would prefer if this one got merged, but if you are keen to have your own suite of tests on isEqual, then #4915 is the way to go.

@benjamn
Copy link
Member

benjamn commented Jun 4, 2019

I didn't say anything about tests in my previous comment, so I don't understand what you're objecting to. I see no reason to remove isEqual from apollo-utilities, and no reason to add new dependencies to the other packages.

@benjamn benjamn closed this Jun 4, 2019
@capaj
Copy link
Contributor Author

capaj commented Jun 4, 2019

@benjamn do you really think having a utility function like this is beneficial to the apollo-client's codebase: https://github.com/capaj/apollo-client/blob/3e992f93328a94cdb5ef66795cef417d6df25698/packages/apollo-utilities/src/util/isEqual.ts#L6
?

I know you can't merge this and release it just with a simple patch bump. I am not asking you to. I just think wrapping lodash with an extra function is not desirable in any JS codebase. SO IMHO best would be to deprecate it, release a patch. Then remove it and release a new major with the function removed.

@benjamn benjamn added this to the Release 3.0 milestone Jun 4, 2019
@benjamn
Copy link
Member

benjamn commented Jun 4, 2019

Adding this to the 3.0 milestone so we can revisit whether isEqual needs to exist in the context of other breaking changes.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 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

Successfully merging this pull request may close these issues.

3 participants