404 flashes when opening site

I am developing a public site with Gatsby for displaying products which has a fetch in src/component/products/index.js. The actual main page looks like this in src/pages/index.js

import React from "react"
import Layout from "../components/Layout"
import Seo from "../components/Seo"
import Product from "../components/product/index"

const IndexPage = () => (
  <Layout>
    <Seo title="Home" />
    <Product />
  </Layout>
)

export default IndexPage

My sit works great and product page shows product info from REST call nicely but the problem here as that when I load my site the 404.js is displayed for 1-2secs:

import React from "react"
import Layout from "../components/Layout"
import Seo from "../components/Seo"
import NotFound from "../components/NotFound"

const NotFoundPage = () => (
  <Layout>
    <Seo title="Not found" />
    <NotFound />
  </Layout>
)

export default NotFoundPage

The NotFound is in src/components/NotFound.js

Why is this happening? Locally with Gatsby development this does not happen but with Netlify it does? I am not sure what to look for here.

Hi @teemualander,

Which website are we talking about? Your account doesn’t seem to have any website. Do let us know if something has changed.

This is the site: https://productreimacom.netlify.app/531485-0100

The page indeed returns a 404:

And it seems like you’ve a JavaScript-based redirect that does its job once the page has loaded. I can confirm this because if I disable the JavaScript, the redirect doesn’t work. It sticks to the 404 page. It’s not happening locally probably because development servers are usually faster because they’re serving locally. Maybe if you try and simulate network conditions to slower it will reproduce the same error there.

My suggestion would be to develop an index.html for each page and show some loading indication there instead of relying on JavaScript redirects. But then, if it’s not possible, you can try adding the following redirect rule:

/* /index.html 200

The above text goes in a _redirects file in the static folder (in the case of Gatsby).