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

[3.0] EntityStore error after calling cache.evict #5793

Closed
jamshally opened this issue Jan 15, 2020 · 2 comments · Fixed by #5796
Closed

[3.0] EntityStore error after calling cache.evict #5793

jamshally opened this issue Jan 15, 2020 · 2 comments · Fixed by #5796
Assignees
Milestone

Comments

@jamshally
Copy link

Scenario
Executing the following line of code:

  apolloClient.cache.evict(defaultDataIdFromObject(user));

Intended outcome:
Evict succeeds, with no subsequent error

Actual outcome:
An error is thrown with the following message: TypeError: Cannot convert undefined or null to object

The following further info is shown in the error details:

TypeError: Cannot convert undefined or null to object
Layer.EntityStore.get
entityStore.js:28
  25 |     var storeObject = this.data[dataId];
  26 |     if (!fieldName)
  27 |         return storeObject;
  28 |     if (hasOwn.call(storeObject, fieldName)) {
  29 |         return storeObject[fieldName];
  30 |     }
  31 | }

How to reproduce the issue:
This error started just by adding cache.evict. I am not entirely sure of the prerequisite conditions. I will spend time reproducing in the apollo error template if the cause of this issue is not obvious to the apollo team

Versions
System:
OS: macOS 10.15.2
Binaries:
Node: 13.6.0 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Browsers:
Chrome: 79.0.3945.117
Safari: 13.0.4
npmPackages:
@apollo/client: v3.0.0-beta.23 => 3.0.0-beta.23
@apollo/react-hooks: ^3.2.0-beta.0 => 3.2.0-beta.0
apollo-link-debounce: ^2.1.0 => 2.1.0

@hwillson hwillson added this to the Release 3.0 milestone Jan 15, 2020
@benjamn benjamn self-assigned this Jan 15, 2020
@benjamn
Copy link
Member

benjamn commented Jan 15, 2020

Ahh, this looks like a missing storeObject truthiness check introduced in #5772. Dangling references are supposed to be handled gracefully.

@benjamn
Copy link
Member

benjamn commented Jan 15, 2020

Also, there's a new cache.identify method that allows you to write

 apolloClient.cache.evict(apolloClient.cache.identify(user));

which respects keyFields, whereas defaultDataIdFromObject is only good for IDs computed by dataIdFromObject.

benjamn added a commit that referenced this issue Jan 16, 2020
Should fix #5793, which was due to a bug I introduced in #5772.
@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

Successfully merging a pull request may close this issue.

3 participants