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

Navigating from 404 page errors on production deployment #1838

Closed
gtfargo opened this issue Aug 16, 2017 · 24 comments
Closed

Navigating from 404 page errors on production deployment #1838

gtfargo opened this issue Aug 16, 2017 · 24 comments

Comments

@gtfargo
Copy link

gtfargo commented Aug 16, 2017

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",
@kbariotis
Copy link
Contributor

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

@gtfargo
Copy link
Author

gtfargo commented Aug 18, 2017

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

@gtfargo
Copy link
Author

gtfargo commented Aug 24, 2017

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

@gtfargo gtfargo closed this as completed Aug 24, 2017
@kbariotis
Copy link
Contributor

@gtfargo hmm not really, still the same issue.

@mikhail-softgrad
Copy link

mikhail-softgrad commented Aug 28, 2017

I have same issue
@KyleAMathews

@gtfargo gtfargo reopened this Aug 31, 2017
@KyleAMathews
Copy link
Contributor

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

@kbariotis
Copy link
Contributor

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

@gtfargo
Copy link
Author

gtfargo commented Sep 1, 2017

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)
      }
    }

@KyleAMathews
Copy link
Contributor

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.

@attfarhan
Copy link
Contributor

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

@kbariotis
Copy link
Contributor

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.

@revolunet
Copy link

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

@johnryan
Copy link

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?

@KyleAMathews
Copy link
Contributor

This is still an issue.

@efallancy
Copy link
Contributor

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

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Oct 29, 2017 via email

@revolunet
Copy link

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

@efallancy
Copy link
Contributor

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

@revolunet
Copy link

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

btw, i see PR #2667 is getting some love, so it may be better to focus on that real fix :)

@efallancy
Copy link
Contributor

ah, right 😅 i see what you mean.

@mickeyreiss-visor
Copy link
Contributor

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.

@KyleAMathews
Copy link
Contributor

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

@mickeyreiss-visor
Copy link
Contributor

Thanks, @KyleAMathews!

For others in a similar situation, it looks like @emmafallancy's fix landed via #2667 and was released in gatsby@1.9.110.

@janosh
Copy link
Contributor

janosh commented Sep 16, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants