Gatsby: "Uncaught (in promise) Error: 404 page could not be found" when pressing back button

Created on 17 Aug 2019  路  3Comments  路  Source: gatsbyjs/gatsby

Description

I find sometimes when pressing the back button, then from there clicking on another link, nothing happens. I see this in the console: app-fe7c17e2944200c5b471.34096c386004d3b05de6e33102e6278b.js:1 Uncaught (in promise) Error: 404 page could not be found. Checkout https://www.gatsbyjs.org/docs/add-404-page/ at app-fe7c17e2944200c5b471.34096c386004d3b05de6e33102e6278b.js:1.

Steps to reproduce

  1. go to https://www.fgbg.art
  2. click on a link, then a thumbnail to arrive at a detail page
  3. press back button to return to list page
  4. click on another thumbnail

Expected result

goes to other detail page

Actual result

error in console as noted above.

Environment

System:
OS: Linux 4.15 Ubuntu 18.04.3 LTS (Bionic Beaver)
CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
Yarn: 1.12.3 - ~/.yarn/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
Languages:
Python: 2.7.15+ - /usr/bin/python
Browsers:
Chrome: 76.0.3809.100
Firefox: 68.0.1
npmPackages:
gatsby: ^2.13.20 => 2.13.20
gatsby-plugin-favicon: ^3.1.6 => 3.1.6
gatsby-plugin-google-analytics: ^2.1.4 => 2.1.4
gatsby-plugin-manifest: ^2.2.3 => 2.2.3
gatsby-plugin-offline: ^2.2.4 => 2.2.4
gatsby-plugin-react-helmet: ^3.1.2 => 3.1.2
gatsby-plugin-sharp: ^2.2.7 => 2.2.7
gatsby-plugin-typescript: ^2.1.2 => 2.1.2
gatsby-source-filesystem: ^2.1.5 => 2.1.5
gatsby-source-google-sheets: ^1.1.1 => 1.1.1
gatsby-transformer-csv: ^2.1.2 => 2.1.2
gatsby-transformer-sharp: ^2.2.3 => 2.2.3

More context

I think this only happens if I have the site loaded in my browser, and I deploy a new version.

The site is hosted on gh-pages, and thus I had the other problem of stale page-data.json files being used, so I employed the hack of adding a sha to basically all non-html files as described here. Here is the terrible code I wrote to do this.

If I refresh the page, everything works again as expected.

I suspect if I took the above sha hack out, this problem would go away. But then I'd be back to the stale page-data.json problem. I'm far from a gatsby expert, but it feels like being stuck between a rock and a hard place when using gh-pages. Maybe gatsby really is intended to be used in situations when you have control over the headers the server sets on responses?

Most helpful comment

A static site generator that doesn't support one of the most popular static site hosting solutions is indeed unfortunate :(

All 3 comments

I've tested your site. I don't have any issues with the forward & back buttons. You're saying that it only occurs when a new deploy occurs.

I do reckon that there is an issue with GitHub pages and Gatsby. I'm not sure we can help you any further with this issue as you've changed some internals. I'll be closing this issue. We probably want to move this discussion to #15080. We might need to drop support for GitHub pages...

A static site generator that doesn't support one of the most popular static site hosting solutions is indeed unfortunate :(

Fair point :smile: Let's move the discussion to #15080 and hopefully we can get this resolved, I have a few ideas around cache busting.

Or feel free to open a new issue that says github pages is broken :) that's probably a better way to go forward.

Was this page helpful?
0 / 5 - 0 ratings