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

Uncaught TypeError: Cannot read property 'index' of undefined #708

Open
theWebalyst opened this issue Jun 12, 2019 · 1 comment

Comments

1 participant
@theWebalyst
Copy link

commented Jun 12, 2019

Here's the full stack trace.

Uncaught TypeError: Cannot read property 'index' of undefined
    at HistoryHandler.handlePop (main.chunk.js:99361)
    at main.chunk.js:99310
    at listener (1.chunk.js:28923)
    at 1.chunk.js:28941
    at Array.forEach (<anonymous>)
    at Object.notifyListeners (1.chunk.js:28940)
    at setState (1.chunk.js:29061)
    at 1.chunk.js:29084
    at Object.confirmTransitionTo (1.chunk.js:28913)
    at handlePop (1.chunk.js:29082)
    at handlePopState (1.chunk.js:29067)

This error occurs when handlePopState(event) is called with error.state set to null. If it were undefined it would be filtered out by the call to isExtraneousPopstateEvent(event) which checks if event.state is undefined:

export function isExtraneousPopstateEvent(event) {
return event.state === undefined && navigator.userAgent.indexOf('CriOS') === -1;
}

It is hard to reproduce the circumstances for you because it is occurring in a custom built Chrome based browser, that is designed only for use with the SAFE Network (not the http web).

Environment etc

What I've noticed so far is:

  • it happens in a react app
  • that app is using history v4.9.0
  • so far the error comes and goes with changes to the build of the app and/or other modules I'm working on
  • the error only occurs on first load of the app, but goes away if I refresh the page in the browser

I don't know what causes event.state to be null, but it is intermittent, and build dependent.

Solution

I suggest modifying isExtraneousPopstateEvent(event) to the following:

export function isExtraneousPopstateEvent(event) {
  return (!event.state === undefined || event.state === null) && navigator.userAgent.indexOf('CriOS') === -1;
}

NOTE: I'm trying to verify this myself with a local build via yarn link but my version is not yet being picked up for some reason, but will submit this anyway. UPDATE: I've now verified the above fix solves the problem which I have.

@theWebalyst

This comment has been minimized.

Copy link
Author

commented Jun 12, 2019

Would you accept a PR for the above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.