Skip to content

fix(gatsby): fetching 404 page with path prefix #34237

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions e2e-tests/path-prefix/cypress/integration/navigate.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ describe(`navigate`, () => {

cy.get(`h1`).contains(`NOT FOUND`)
})

it(`can load 404 page and react client side rendering success`, () => {
cy.visit(`/not-existing-page`, {
failOnStatusCode: false,
}).waitForRouteChange()

cy.getTestElement(`page-404-click`).click()

cy.get(`h2`).contains(`gatsby`)
})
})
18 changes: 12 additions & 6 deletions e2e-tests/path-prefix/src/pages/404.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as React from "react"
import Layout from "../components/layout"

const NotFoundPage = () => (
<Layout>
<h1>NOT FOUND</h1>
<p>You just hit a route that doesn&#39;t exist... the sadness.</p>
</Layout>
)
const NotFoundPage = () => {
const [company, setCompany ] = React.useState("")

return (
<Layout>
<h1>NOT FOUND</h1>
<h2>{company}</h2>
<p>You just hit a route that doesn&#39;t exist... the sadness.</p>
<button data-testid="page-404-click" onClick={() => { setCompany("gatsby") }}>Click</button>
</Layout>
)
}

export default NotFoundPage
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ export class ProdLoader extends BaseLoader {
if (data.notFound) {
// check if html file exist using HEAD request:
// if it does we should navigate to it instead of showing 404
return doFetch(rawPath, `HEAD`).then(req => {
return doFetch(`${__PATH_PREFIX__}${rawPath}`, `HEAD`).then(req => {
if (req.status === 200) {
// page (.html file) actually exist (or we asked for 404 )
// returning page resources status as errored to trigger
Expand Down