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

UseFragment producing a warning during store misses (TypeError: Cannot read properties of undefined) #12051

Closed
alex-e-leon opened this issue Sep 3, 2024 · 7 comments · Fixed by #12052
Labels

Comments

@alex-e-leon
Copy link

Issue Description

Since @apollo/client 3.11.5 I've started receiving warnings in the console during store misses of useFragment in development: TypeError: Cannot read properties of undefined (reading '__typename')

A bit of testing suggests that this happens in all my uses of useFragment during store misses.
Note that although I get the warning, everything continues to work fine. @apollo/client 3.11.4 did not have this issue.

In case it's relevant I'm using the following arguments on useFragment: fragment, fragmentName, from: {__typename: X, id: X}

The full stack trace is:

TypeError: Cannot read properties of undefined (reading '__typename')
    at Policies2.identify (policies.ts:360:14)
    at InMemoryCache2.identify (inMemoryCache.ts:350:28)
    at ApolloCache2.watchFragment (cache.ts:232:50)
    at useFragment.ts:105:36
    at subscribeToStore (react-dom.development.js:16139:10)
    at commitHookEffectListMount (react-dom.development.js:23189:26)
    at invokePassiveEffectMountInDEV (react-dom.development.js:25193:13)
    at invokeEffectsInDev (react-dom.development.js:27390:11)
    at commitDoubleInvokeEffectsInDEV (react-dom.development.js:27369:7)
    at flushPassiveEffectsImpl (react-dom.development.js:27095:5)

Link to Reproduction

None

Reproduction Steps

Call useFragment on any fragment which hasn't been loaded into the FE cache/store by typename + id.

@apollo/client version

3.11.5

@jerelmiller
Copy link
Member

Hey @alex-e-leon!

You beat me to opening this 😆. I discovered this just recently working with the data masking feature. We did some rework with useFragment to ensure it follows the Rules of React (specifically not writing to ref in render), but I just found out that causes this warning. I know exactly where the issue is coming from so I'll get a PR out for this very soon (hopefully today). So sorry about the additional noise!

@alex-e-leon
Copy link
Author

This is the punishment I get for staying up to date with all the latest deps : )

And thanks @jerelmiller - its great to get such fast feedback and see that you're already on top of it!

@jerelmiller
Copy link
Member

Not on you 😆. We unfortunately had a missing test so we didn't see the regression on our end.

I just opened #12052 which should fix the issue. Could you try this snapshot release to see if the warning goes away?

npm i @apollo/[email protected]

Copy link
Contributor

github-actions bot commented Sep 4, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

@alex-e-leon
Copy link
Author

@jerelmiller - sorry, I've been super busy this week, so probably don't have time to test the branch right now. But looks like you guys are on top of it. Thanks for the quick response and looking forward to seeing it in the next release!

@jerelmiller
Copy link
Member

You're welcome! I just got it released so you can to upgrade to 3.11.7 and the warning should disappear. Thanks again for reporting the issue!

Copy link
Contributor

github-actions bot commented Oct 6, 2024

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 github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants