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

Invariant Violation 17 #5291

Closed
RIP21 opened this issue Sep 9, 2019 · 12 comments
Closed

Invariant Violation 17 #5291

RIP21 opened this issue Sep 9, 2019 · 12 comments

Comments

@RIP21
Copy link

RIP21 commented Sep 9, 2019

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.

@benjamn
Copy link
Member

benjamn commented Sep 10, 2019

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.

@RIP21
Copy link
Author

RIP21 commented Sep 10, 2019

@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?

@benjamn
Copy link
Member

benjamn commented Sep 12, 2019

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.

@RIP21
Copy link
Author

RIP21 commented Sep 12, 2019

@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",

@Enigma10
Copy link

@benjamn we are also getting the same issue on sentry.
Apollo client version:
"apollo-client": "^2.6.4"

@yassinebridi
Copy link

this happened to me today, only in production:
"apollo-client": "^2.6.4"

@OscarYuen
Copy link

OscarYuen commented Oct 5, 2019

Yes, I got those error from sentry that those users are using iOS
"apollo-client": "^2.6.4"

@shockdesign
Copy link

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.

@MrWook
Copy link

MrWook commented Oct 22, 2019

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
#4114
apollographql/apollo-feature-requests#107

If you are using fetch more you can catch it with try/catch #4114 (comment)

@RIP21
Copy link
Author

RIP21 commented Oct 27, 2019

@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 :(

benjamn added a commit that referenced this issue Jul 21, 2020
When an invariant fails in production, a cryptic numeric error of the form
`Invariant Violation: 42` is thrown, with a reference to the error codes
section of invariant-packages README.md: https://github.com/apollographql/invariant-packages#error-codes

This vague guidance has not proven adequate in many cases, to say the
least: see apollographql/invariant-packages#18,
apollographql/invariant-packages#19, #6604,

However, this vague guidance (which was intended to suggest searching
your installed node_modules/@apollo/client package for the error code)
has not proven adequate in many cases, to say the least: see apollographql/invariant-packages#18,
apollographql/invariant-packages#19, #6604, #5730, #5291, and #5975,
to cite just a few of the many issues we've seen since #4521.

Using error codes instead of error strings remains important for
production bundle sizes, but I think we can make it substantially easier
to look up the error string corresponding to each error code, by
generating a single file containing all the invariant error codes for each
@apollo/client release.

Starting with Apollo Client 3.1.0, this manifest file can be found in
@apollo/client/invariantErrorCodes.js (using an npm/yarn-installed copy of
@apollo/client, since this file is generated in the ./dist directory, not
checked into the repository). The file contains an explanatory comment,
the @apollo/client version, and a sequential map from error numbers to the
{ file, node } responsible for the error.
jimrandomh pushed a commit to jimrandomh/apollo-client that referenced this issue Jul 22, 2020
…llographql#6665)

When an invariant fails in production, a cryptic numeric error of the form
`Invariant Violation: 42` is thrown, with a reference to the error codes
section of invariant-packages README.md: https://github.com/apollographql/invariant-packages#error-codes

This vague guidance has not proven adequate in many cases, to say the
least: see apollographql/invariant-packages#18,
apollographql/invariant-packages#19, apollographql#6604,

However, this vague guidance (which was intended to suggest searching
your installed node_modules/@apollo/client package for the error code)
has not proven adequate in many cases, to say the least: see apollographql/invariant-packages#18,
apollographql/invariant-packages#19, apollographql#6604, apollographql#5730, apollographql#5291, and apollographql#5975,
to cite just a few of the many issues we've seen since apollographql#4521.

Using error codes instead of error strings remains important for
production bundle sizes, but I think we can make it substantially easier
to look up the error string corresponding to each error code, by
generating a single file containing all the invariant error codes for each
@apollo/client release.

Starting with Apollo Client 3.1.0, this manifest file can be found in
@apollo/client/invariantErrorCodes.js (using an npm/yarn-installed copy of
@apollo/client, since this file is generated in the ./dist directory, not
checked into the repository). The file contains an explanatory comment,
the @apollo/client version, and a sequential map from error numbers to the
{ file, node } responsible for the error.
@hwillson
Copy link
Member

#6665 was merged and released to help make tracing errors like this easier. Please try out a more modern version of @apollo/client, and let us know if you're still encountering issues. Thanks!

@jaedb
Copy link

jaedb commented Sep 7, 2021

This is relieving to see other users experiencing the same bug. Can anyone calm my nerves on this by confirming whether it crashes the app/component or is it a silent error that does not affect the user? I have had zero luck replicating the issue but it definitely occurs ~daily (reported by Sentry).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 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

No branches or pull requests

9 participants