Gatsby: Navigating from 404 page errors on production deployment

Created on 16 Aug 2017  ยท  24Comments  ยท  Source: gatsbyjs/gatsby

When a user attempts to navigate _from_ the 404 page on a production build, the console shows this error and the page never redirects:

Uncaught TypeError: Cannot read property 'push' of undefined
    at eventHandler (production-app.js:51)
    at mitt.js:1
    at Array.map (<anonymous>)
    at Object.emit (mitt.js:1)
    at done (loader.js:284)
    at loader.js:295
    at loader.js:95
    at loader.js:78
    at index.js?d7c6:11
    at handler (patch.js:18)

or, if content for the desired destination is already loaded:

Cannot read property 'push' of undefined
    at navigateTo (production-app.js:66)
    at t.navigateTo (index.js:154)
    at gatsby-browser.js:12
    at catch-links.js:51

404.js

import React from 'react';
import Link from 'gatsby-link';

const NotFoundPage = () =>
  <div>
    <h1>NOT FOUND</h1>
    <Link to={`/`}>Click here to go home</Link>
  </div>;

export default NotFoundPage;

dependency versions:

"gatsby": "^1.8.11",
"gatsby-link": "^1.6.7",
"gatsby-plugin-catch-links": "^1.0.4",

Most helpful comment

That'd be great!

On Sat, Oct 28, 2017, 6:36 PM Emmanuel Fallancy notifications@github.com
wrote:

@KyleAMathews https://github.com/kyleamathews I can get this done if
you don't mind ๐Ÿ˜ƒ This particularly happened when there's no history
being pushed to window.___history

โ€”
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/gatsbyjs/gatsby/issues/1838#issuecomment-340231314,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEVhx74TnYQtMCmOpE_ykrpSH4DJT3vks5sw9apgaJpZM4O5aAe
.

All 24 comments

I have the same error using a gatsby-link at my 404 component.

Attempted to reproduce with a the boilerplate example... Seems my personal deployment is causing the issue. Still digging into this for more info.

Seems the most recent update has fixed this, @kbariotis try updating.

@gtfargo hmm not really, still the same issue.

I have same issue
@KyleAMathews

One of you want to take a crack at fixing this?

@KyleAMathews Sure I will. Could you please guide me to the right direction in the codebase, since I haven't touched it before?

In the if statement of this eventHandler in production-app.js the event value is _only_ the to value of the gatsby-link. In my case, "/"

function eventHandler(e) {
      if (e.page.path === loader.getPage(pathname).path) {
        emitter.off(`onPostLoadPageResources`, eventHandler)
        clearTimeout(timeoutId)
        window.___history.push(pathname)
      }
    }

The error is happening in https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/production-app.js

Follow the contributing instructions so you can develop against the checked out version of Gatsby and start adding console.logs to understand why there's the failure.

@KyleAMathews @kbariotis @gtfargo I also just ran into this issue. Anything we can do to get the PR updated and merged soon?

Im sorry @attfarhan didn't find the time to work on it :/ I need it too so I will try to check it again soon.

same here; some more info; quite critical because once the user lands on a 404, he can never navigate again

capture d ecran 2017-10-06 a 11 47 09

capture d ecran 2017-10-06 a 11 47 21

fwiw this doesn't just affect links, it seems like none of the JS is being loaded in, (i.e. code called in componentDidMount is executed). @KyleAMathews is this a separate issue or is this resolved in your PR?

This is still an issue.

@KyleAMathews I can get this done if you don't mind ๐Ÿ˜ƒ This particularly happened when there's no history being pushed to window.___history

That'd be great!

On Sat, Oct 28, 2017, 6:36 PM Emmanuel Fallancy notifications@github.com
wrote:

@KyleAMathews https://github.com/kyleamathews I can get this done if
you don't mind ๐Ÿ˜ƒ This particularly happened when there's no history
being pushed to window.___history

โ€”
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/gatsbyjs/gatsby/issues/1838#issuecomment-340231314,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEVhx74TnYQtMCmOpE_ykrpSH4DJT3vks5sw9apgaJpZM4O5aAe
.

in the meantime, any idea how to disable client-side on pages/404.js only ?

@revolunet do you mean as not using the pages/404.js page in production?

no i mean, juste disable the client-side javascript on that page so links are clickable :)

btw, i see PR https://github.com/gatsbyjs/gatsby/pull/2667 is getting some love, so it may be better to focus on that real fix :)

ah, right ๐Ÿ˜… i see what you mean.

Has anyone made meaningful progress on the fix? This is a user-impactful bug.

@KyleAMathews Do you have a sense of where the issue lies? I'd be willing to take a try at the fix.

@mikhail-softgrad this is fixed actually :-) @emmafallancy did several PRs a month or so ago so closing this now.

Thanks, @KyleAMathews!

For others in a similar situation, it looks like @emmafallancy's fix landed via https://github.com/gatsbyjs/gatsby/pull/2667 and was released in [email protected].

It appears as though this issue was not yet fixed in v2. Can someone confirm this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timbrandin picture timbrandin  ยท  3Comments

dustinhorton picture dustinhorton  ยท  3Comments

kalinchernev picture kalinchernev  ยท  3Comments

magicly picture magicly  ยท  3Comments

ferMartz picture ferMartz  ยท  3Comments