apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

Cache keys are being stored with spaces some of the time

Open jcollum-nutrien opened this issue 2 years ago • 1 comments

I put this up on StackOverflow, asking if it might be some config issue on our end. No responses.

Intended outcome:

I'd like cache keys to always be stored in the same pattern. The delta is causing re-renders in our React code. I suspect the real solution is to not depend on the Apollo client (I assume it's a singleton) but some of our code is depending on it and my team will need to get approval to change it. Anyway when I looked at the object in cache this seemed very odd so I'm putting it up as a bug. I could not find any place in our code where these keys are being created.

I might be wrong, this might be our problem. I can't find it though. This object is pretty deep in the Apollo object.

Actual outcome:

Cache keys are "Account:1107716" some of the time and "Account: 1107716" some of the time.

Diff:

image

I can provide the entire object (with circulars taken out) if needed, I'll just have to replace the sensitive info.

Here's what the collapsed object looks like:

image

How to reproduce the issue:

All I can say is that we retrieved some accounts from an endpoint and ran Why Did You Render (a React tool) on the page. WDYR reported that there was a diff between the two cache objects which caused a React component to re-render.

Versions

System:
    OS: macOS 12.5.1
  Binaries:
    Node: 14.19.1 - ~/.nvm/versions/node/v14.19.1/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v14.19.1/bin/yarn
    npm: 6.14.16 - ~/.nvm/versions/node/v14.19.1/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
    Safari: 15.6.1

jcollum-nutrien avatar Aug 29 '22 17:08 jcollum-nutrien

@jcollum-nutrien This is how Apollo Client generates cache keys by default. Is it possible your id is coming back from your GraphQL endpoint somewhere prefixed with the extra space? If so it will end up in the cache key, so I'd recommend checking there first. If that doesn't help are you customizing your cache keys anywhere by using keyFields? If so maybe the extra space is getting in that way.

hwillson avatar Sep 12 '22 10:09 hwillson

We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you!

github-actions[bot] avatar Feb 17 '23 05:02 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.

github-actions[bot] avatar Mar 20 '23 00:03 github-actions[bot]