gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.19k stars 10.33k forks source link

Page 404 redirects to ?no-cache=1 #8297

Closed robertoaikode closed 5 years ago

robertoaikode commented 5 years ago

Description

I'm using Gatsby V2. I have a strange problem with 404 error because it redirects automatically to ?no-cache=1

My URL is: https://aikode-pwa-sistema.firebaseapp.com/

Steps to reproduce

I executed:

Expected result

show URL without "?no-cache=1"

https://aikode-pwa-sistema.firebaseapp.com/page-test-404

Actual result

show URL with "?no-cache=1"

https://aikode-pwa-sistema.firebaseapp.com/page-test-404?no-cache=1

Environment

System: OS: Windows 10 CPU: x64 Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz Binaries: Yarn: 1.7.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 5.6.0 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 42.17134.1.0 npmPackages: gatsby: ^2.0.0 => 2.0.1 gatsby-plugin-manifest: ^2.0.2 => 2.0.2 gatsby-plugin-nprogress: ^2.0.5 => 2.0.5 gatsby-plugin-offline: ^2.0.5 => 2.0.5 gatsby-plugin-react-helmet: ^3.0.0 => 3.0.0 gatsby-plugin-remove-trailing-slashes: ^2.0.0 => 2.0.0

devrchancay commented 5 years ago

Hello, that problem seems more like firebase than gatsby. If you try to upload your application to netlify?

robertoaikode commented 5 years ago

@devrchancay but also happens with gatsby serve (http://localhost:9000)

KyleAMathews commented 5 years ago

@davidbailey00 can't we avoid showing ?no-cache=1 if there is a 404.js component?

devrchancay commented 5 years ago

It's super weird, I have a project with version 2 with similar dependencies to yours and that does not happen to me, I just verified it, will not you have something like that in your 404 component?

kakadiadarpan commented 5 years ago

@devrchancay this will only happen if you have added gatsby-plugin-offline in your application.

vtenfys commented 5 years ago

@robertoaikode This is intentional behaviour in order to prevent incorrectly displaying a 404 page - I'll have a look next week to see if I can improve how it works.

devrchancay commented 5 years ago

@kakadiadarpan I am using the offline plugin, as I read is a normal behavior but it does not happen for sure I have to update something. image

drewhamlett commented 5 years ago

I'm getting this same thing in production. Only plugins I have. Everything up to date

plugins: [
    'gatsby-plugin-react-helmet',
    {
      resolve: 'gatsby-plugin-sass',
      options: {
        precision: 8,
      },
    },
  ],
vtenfys commented 5 years ago

@drewhamlett Actually this will occur without using the offline plugin too - I'll try to make some changes next week which improve the behaviour.

vtenfys commented 5 years ago

can't we avoid showing ?no-cache=1 if there is a 404.js component?

@KyleAMathews yep that sounds good! Worth noting that it'll still be necessary in some circumstances e.g. Netlify CMS + offline plugin (otherwise the offline shell would try handling the request).

robertoaikode commented 5 years ago

@davidbailey00 thanks 😄

bogdancss commented 5 years ago

happening on our website as well: https://www.kaizen.co.uk/adsdafa redirects to https://www.kaizen.co.uk/adsdafa?no-cache=1 which actually causes the page transition (using react-transition-group) to fail. Also here's the log from inspector:

A page wasn't found for "/adsdafa"
load-directly-or-404.js:18 Found no-cache=1 while attempting to load a page directly; this is likely due to a bug in Gatsby, or a misconfiguration in your project.
vtenfys commented 5 years ago

@b0gd4n Interesting, that error message actually indicates that there's something wrong with the 404 page itself, and Gatsby prevented an infinite loop. I'll definitely investigate this on Monday

vtenfys commented 5 years ago

Also I just noticed this is happening on Gatsby's own website; it looks like a recent change broke something. Sorry about all the problems :(

image

abstracthat commented 5 years ago

I'm getting a refresh loop that keeps appending that query string on our homepage that does exist. The page is not 404 and is trying to load on each refresh with another no-cache query string appended.

dbrookes commented 5 years ago

@abstracthat I'm seeing the same thing, Googlebot and Page Speed are complaining the homepage is a redirect loop as you described, but it doesn't happen in Chrome/Firefox for me.

Struggling to reproduce it on Netlify, will keep trying

abstracthat commented 5 years ago

@dbrookes I fixed it. I was using an undeclared variable but the error was swallowed in dev. I suspect this is the actual issue. The page JS couldn't load correctly so it thought it was not found but the router says load this file, so it got stuck in a loop. In the same deploy I also updated to the latest Gatsby plugins (minor point versions), so it's also possible that was the fix, but I suspect the latter.

vtenfys commented 5 years ago

@abstracthat With the latest changes, the infinite loops have been fixed so now you'll see a console log saying "Found ?no-cache=1 when trying to directly load page. This is probably a misconfiguration with your app, or a bug with Gatsby" in places where an infinite loop would happen.

chiumax commented 5 years ago

Is this fixed? I get this issue as well.

vtenfys commented 5 years ago

@dumblole The changes were only just published a few hours ago, so if you run yarn upgrade now it should be fixed. Let us know if you're still having any issues :)

robinpyon commented 5 years ago

Can confirm upgrading to gatsby 2.0.10 fixed this for me

chiumax commented 5 years ago

Thanks! Works like a charm. 👌

DavidTheSimon commented 5 years ago

gatsby v2.4.1 still produces this error. Can you please look into this?

vtenfys commented 5 years ago

Hey @DavidTheSimon, please can you open a new issue describing the problem? I'll be happy to have a look at this, but I need a demonstration repository so I can see the cases when it's happening.

N.b. in certain cases, ?no-cache=1 is still required in order to display the correct page so it will still occasionally be displayed in the address bar - if you can open an issue with better proposed behaviour I'd be happy to look into this.

talolard commented 5 years ago

I had this issue with production builds only when serving the site from S3/Cloudfront I had forgotten to tell S3 where the 404 page is, and it returned the no-cache thing. Setting the error document fixed it image

mikbeach commented 5 years ago

I had this issue on a production build when serving from an Azure Web App. It seems obvious now but you need to have a Web.Config file which will redirect 404 errors to the /404/index.html page. I created my web.config and put it in the static folder so is inserted in the public folder on build.

The part of my web.config which needed to be added:

<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" path="/404/index.html" responseMode="ExecuteURL" /
</httpErrors>
DavidTheSimon commented 5 years ago

Thanks @mikbeach, that sounds promising. Never thought of that. I'll definitely give it a go next week and get back here with my results on Nginx server.

rotexhawk commented 5 years ago

Running into the same issue. gatsby 2.0

vtenfys commented 5 years ago

@rotexhawk The ?no-cache parameter has been removed from recent versions of Gatsby, please update your plugins and try again :)