Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[now-next] Update 404 handling for pages/404 (#3697)
This adds handling for treating `pages/404.js` as the custom error page in Next.js to allow for more flexible auto static optimization on the 404 page. This makes sure we handle `pages/404.js` being a lambda due to `_app` having `getInitialProps` and also makes sure that visiting `/404` doesn't respond with a 200 status code ~We can add tests for this behavior after the below PR has been released in a canary of Next.js~ x-ref: vercel/next.js#10329 x-ref: vercel/next.js#10593
- Loading branch information
Showing
14 changed files
with
114 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
generateBuildId() { | ||
return 'testing-build-id'; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"version": 2, | ||
"builds": [{ "src": "package.json", "use": "@now/next" }], | ||
"probes": [ | ||
{ | ||
"path": "/", | ||
"mustContain": "Hi" | ||
}, | ||
{ | ||
"path": "/", | ||
"responseHeaders": { | ||
"x-now-cache": "HIT" | ||
} | ||
}, | ||
{ | ||
"path": "/non-existent", | ||
"mustContain": "custom 404!!" | ||
}, | ||
{ | ||
"path": "/non-existent", | ||
"mustContain": "__next" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"next": "9.2.3-canary.4", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'custom 404!!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'Hi'; |
5 changes: 5 additions & 0 deletions
5
packages/now-next/test/fixtures/20-pages-404-lambda/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
generateBuildId() { | ||
return 'testing-build-id'; | ||
}, | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/now-next/test/fixtures/20-pages-404-lambda/now.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"version": 2, | ||
"builds": [{ "src": "package.json", "use": "@now/next" }], | ||
"probes": [ | ||
{ | ||
"path": "/", | ||
"mustContain": "Hi" | ||
}, | ||
{ | ||
"path": "/non-existent", | ||
"mustContain": "custom 404!!" | ||
}, | ||
{ | ||
"path": "/non-existent", | ||
"mustContain": "__next" | ||
} | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/now-next/test/fixtures/20-pages-404-lambda/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"next": "9.2.3-canary.4", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/now-next/test/fixtures/20-pages-404-lambda/pages/404.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'custom 404!!'; |
5 changes: 5 additions & 0 deletions
5
packages/now-next/test/fixtures/20-pages-404-lambda/pages/_app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const App = ({ Component, pageProps }) => <Component {...pageProps} />; | ||
|
||
App.getInitialProps = () => ({ hello: 'world' }); | ||
|
||
export default App; |
1 change: 1 addition & 0 deletions
1
packages/now-next/test/fixtures/20-pages-404-lambda/pages/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'Hi'; |