Skip to content
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

Remove default export of a 404.html.html page #36857

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,8 @@ export default async function exportApp(
})
)

if (
!options.buildExport &&
!exportPathMap['/404'] &&
!exportPathMap['/404.html']
) {
exportPathMap['/404'] = exportPathMap['/404.html'] = {
if (!options.buildExport && !exportPathMap['/404']) {
exportPathMap['/404'] = {
page: '/_error',
}
}
Comment on lines -421 to 425
Copy link
Contributor

@SukkaW SukkaW May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it is not the correct fix.

The code here is designed to work like this:

  • When you specify a custom 404 in exportPathMap:
    • Next.js shouldn't overwrite your custom 404 export alias.
  • When you don't specify a custom 404 in exportPathMap (when, and only when neither /404 nor /404.html exists in exportPathMap):
    • When trailingSlash is disabled (which is by default):
      • only 404.html should be exported (which could be used to render https://example.com/404).
      • ['/404', '/404.html'] will be deduped to /404 after path normalization
    • When trailingSlash is enabled:
      • should export 404/index.html instead (which could be used to render https://example.com/404/).
      • A 404.html should also be exported for backward compatibility with GitHub Pages, GitLab Pages, Cloudflare Pages, Netlify, etc.
      • So, /404 would export /404/index.html and /404.html would export /404.html.

You could take a look at export/worker.ts to see how it handles the 404 (check the isBultinPaths part). Also, an integration test case to verify your fix would be appreciated.

Expand Down