-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Apollo v3.6.8 and above throw Uncaught TypeError: Cannot read properties of undefined (reading 'shift')
when running multiple writeFragment calls in a loop
#10262
Comments
I've been investigating this more and have managed to reproduce the issue, see here: https://codesandbox.io/s/apollo-typeerror-demo-qygfem?file=/src/App.jsx The issue seems to occur when there are any observed queries that use the I've had to downgrade back to Apollo 3.6.7 for the time being, hopefully this issue can be resolved soon so I can upgrade back to the latest version. It's also worth noting that on React 18 this issue seems to be even more pronounced, it happens immediately, without needing any calls to |
Uncaught TypeError: Cannot read properties of undefined (reading 'shift')
when running multiple writeFragment calls in a loop
Any update on this ? It's basically not possible to use the |
I would also appreciate an update on this. This is still preventing me from updating beyond Apollo 3.6.7 or upgrading my app to React 18. I've had a few other issues caused by the |
Fixes issue #10262, since `this.sources.shift()` throws when `complete` is called called before the `Promise` that should have initialized `this.sources` resolves, which can happen when the directive combination `@client @export(as: ...)` is used, because `@export` usage causes a `Promise<Observable[]>` to be passed to the `Concast` constructor instead of the `Observable[]` itself. Although passing a `Promise` to the `Concast` constructor should work, we only exercise that code path in one place, and the additional wrinkle of calling `complete` before the `Promise` resolves was never tested: https://github.com/apollographql/apollo-client/blob/015a1ffff3febe4604956f4bb137a3111f3d8257/src/core/QueryManager.ts#L1226-L1241
Fixes issue #10262, since `this.sources.shift()` throws when `complete` is called called before the `Promise` that should have initialized `this.sources` resolves, which can happen when the directive combination `@client @export(as: ...)` is used, because `@export` usage causes a `Promise<Observable[]>` to be passed to the `Concast` constructor instead of the `Observable[]` itself. Although passing a `Promise` to the `Concast` constructor should work, we only exercise that code path in one place, and the additional wrinkle of calling `complete` before the `Promise` resolves was never tested: https://github.com/apollographql/apollo-client/blob/015a1ffff3febe4604956f4bb137a3111f3d8257/src/core/QueryManager.ts#L1226-L1241
@mogzol @Camsteack Fix incoming! #10526 |
Hey all 👋 It looks like this issue was fixed with 3.7.8 via #10526. I've confirmed this by upgrading the reproduction and verifying the error has gone away. As such, I'm going to go ahead and close this issue. Thanks! |
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. |
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. |
Intended outcome:
This issue occurs when my app makes multiple calls to
client.writeFragment
in a loop, like this:I would expect this to work fine, and it does work fine on all versions of Apollo prior to v3.6.8
Actual outcome:
On v3.6.8 of Apollo and later, on the second iteration of that loop (so the second
writeFragment
call), the following error is thrown:How to reproduce the issue:
Unfortunately I'm not entirely sure how to reproduce this (EDIT: see first comment below for reproduction). I tried creating a new basic Apollo project with a single component and query and then running multiple writeFragments, but couldn't get the error to happen. I can tell you that it does happen reliably in my own app, and the change that caused it was this MR: #9791
Specifically the change to ObservableQuery.ts on line 839:
If I add the second
true
argument back in, then the error is no longer thrown and everything works properly.Versions
The text was updated successfully, but these errors were encountered: