We have this issue that we detect only on Sentry side. Hence I never encountered it myself during development so I have no idea how to reproduce but here is the error message:
Invariant Violation: Invariant Violation: 17 (see https://github.com/apollographql/invariant-packages)
at new t (/static/js/20.3c6f5529.chunk.js:1:129014)
at s (/static/js/20.3c6f5529.chunk.js:1:129219)
at e.getQueryWithPreviousResult (/static/js/20.3c6f5529.chunk.js:1:525535)
at t.updateQuery (/static/js/20.3c6f5529.chunk.js:1:502730)
at None (/static/js/20.3c6f5529.chunk.js:1:501301)
Additional data that sentry provides are:
{
framesToPop: 1
}
Any googling around that didn't help me find what can be the cause of that, but I'll be happy if anyone can give me any idea about this one.
The only clue is that it happens when the user leaves the page with one particular Query out to any different route that unmounts component that uses such query. And it always the same one.
What exact versions of the apollo-*
packages are you using? It's relatively straightforward to track down a specific invariant number given the published bundle, as explained in the README mentioned in the error message you pasted above.
@benjamn
"react-apollo": "^3.0.1",
"@apollo/react-common": "^3.0.1",
"@apollo/react-components": "^3.0.1",
"@apollo/react-hoc": "^3.0.1",
"@apollo/react-hooks": "^3.0.1",
"@apollo/react-testing": "^3.0.1",
This error persists for 2-3 months, so it's there since day 1 we started using Apollo for the piece that causes this Invariant to happen once unmounted while in some unknown state.
It's not that straightforward for me to understand what kind of invariant it's (TBH I do not 100% understand the meaning of the term "invariant")
I can get it from bundle.js
that is got generated from Webpack or what?
I have CRA so adding up some invariant plugin or so is rather hard (possible, but I'm not sure there is Webpack or Babel or whatever version of the Invariant Plugin which, I don't understand what it means and what it does (why not just list of error codes/invariants with explanations?))
Could it be some issue on unmount when there are two records with the same id's but has been fetched using 1 query? So 2 different records of some type, with the same ids in the same response, but slightly different bodies, that drives apollo crazy but only on unmount?
What version of apollo-client
? My guess is that this refers to the invariant
ingetQueryWithPreviousResult
, judging just from the stack trace.
An invariant(condition, message)
function call is an assertion that condition
is truthy, which throws an exception at runtime (with the given message
) if the condition is falsy. The nice thing about the http://npmjs.org/package/ts-invariant package is that we can strip long messages in the production build, which saves more bundle size than any other optimization (besides minification and gzip, of course). In production bundles, the messages are replaced with unique numbers (e.g. 17
), which you can find in the production bundle by looking for invariant(..., 17)
or new InvariantError(17)
. If you examine the surrounding code in a bundle like apollo-client/bundle.esm.js
, you will find a version of the invariant
or InvariantError
with the original message intact. Alternatively, if you can reproduce the error in development, without setting process.env.NODE_ENV === "production"
, then the errors messages will be preserved.
@benjamn Thanks for the guidance, I'll try to repro on dev env. If I will find and issue I'll let you know and will close the issue (if it's not a bug obviously)
Apollo client version:
"apollo-client": "^2.6.4",
@benjamn we are also getting the same issue on sentry.
Apollo client version:
"apollo-client": "^2.6.4"
this happened to me today, only in production:
"apollo-client": "^2.6.4"
Yes, I got those error from sentry that those users are using iOS
"apollo-client": "^2.6.4"
Hitting the same issue for our iOS users, error reported in Sentry as Invariant violation: 17
and we're using "apollo-client": "2.6.4"
as well.
Same problem on multiple devices. The violation 17 means: "ObservableQuery with this id doesn't exist:"
What i found out is that fetchMore queries won't be cancelled and will throw this error.
Ressources
https://github.com/apollographql/apollo-client/issues/4114
https://github.com/apollographql/apollo-feature-requests/issues/107
If you are using fetch more you can catch it with try/catch https://github.com/apollographql/apollo-client/issues/4114#issuecomment-502111099
@MrWook thanks for giving a guess. I think right now I know how it happens and will try to repro and fix this one. It's so annoying it spams a lot of events :(
Most helpful comment
Same problem on multiple devices. The violation 17 means: "ObservableQuery with this id doesn't exist:"
What i found out is that fetchMore queries won't be cancelled and will throw this error.
Ressources
https://github.com/apollographql/apollo-client/issues/4114
https://github.com/apollographql/apollo-feature-requests/issues/107
If you are using fetch more you can catch it with try/catch https://github.com/apollographql/apollo-client/issues/4114#issuecomment-502111099