Revert "Revert "refactor: write pages router export files directly to server/pages/""#93409
Merged
timneutkens merged 5 commits intoMay 26, 2026
Conversation
Contributor
Tests PassedCommit: aab320f |
01e968d to
aab320f
Compare
devjiwonchoi
approved these changes
May 26, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-apply #92735
Before re-landing we need to investigate why the pages router middleware i18n test fails when deployed.
Update: Investigation/fix: #92735 (comment)
Reverts #92733
Cursor plan based on the investigation Claude did:
Fix i18n export orphan HTML files in server/pages/
Problem
When i18n is configured, the export path map in
build/index.tscreates locale-prefixed entries for every page (e.g.,/en/home/a,/fr/home/a), but only deletes the non-locale entry fromdefaultMapfor SSG pages. For non-SSG static pages, the non-locale entry (e.g.,/home/a) remains, causing the export worker to render and write orphan HTML files directly toserver/pages/.These orphan files interfere with routing on deployment platforms (e.g., a
[teamId]/[slug].htmlorphan matches rewritten paths that should 404).Root Cause
In packages/next/src/build/index.ts at line 2988:
The
if (isSsg)guard means non-SSG pages keep their non-locale entry, which gets rendered and written toserver/pages/as an orphan file.Fix
Single-line change in packages/next/src/build/index.ts: Remove the
if (isSsg)guard sodelete defaultMap[page]always runs when i18n is enabled.The locale-prefixed entries are already created in the loop above (line 2981), and they capture the original
pagevalue viadefaultMap[page]?.page || page. The non-locale entry is not needed after that -- in the old staging-directory flow (moveExportedPage), it was rendered but never moved to the final output directory.Safety verification:
updatePagesManifestForExportedPage(line 3754) is called based oncombinedPages, not the export map -- it still correctly replaces non-locale manifest entries with locale-prefixed onespageDurationtracking (line 3745) may returnundefinedfor the non-locale path, but this is typednumber | undefinedand used with|| 0fallback at line 375 ofbuild/utils.ts-- purely cosmeticssgPageDurationsinvariant check (line 3737-3738) only runs for SSG pages, which are unaffectedTest
Add assertions to the existing i18n integration test at test/integration/i18n-support/test/index.test.ts to verify that non-locale-prefixed HTML orphans do not exist in
server/pages/after build. The test already has production mode assertions checking locale-prefixed file existence and manifest correctness (lines 81-99).