Skip to content

Conversation

ztanner
Copy link
Member

@ztanner ztanner commented Apr 4, 2025

When using pages router, we bundle the localized static 404 file with every function output, to ensure that if not found behavior is triggered from a function, that it's available.

However, Next.js prioritizes serving the app router 404 page over the pages router 404 page. As a result, when triggering a not found error from an app router function, it'd trigger a 500 and crash the function because it only knows about en/404.html rather than 404.html (as an example).

This ensures that we bundle the app router 404 page rather than the localized pages router 404 page if i18n + appDir is used. Separately in Next.js we need to ensure the pages-manifest is pointing localized paths to the correct not found file as well. This is accomplished in vercel/next.js#77905

Without that change, this just solves the issue of throwing a 500 rather than resolving a 404 page, but doesn't fix the app router/pages router specificity issue.

Test plan

  • Land this change
  • Land the fix in Next.js
  • Update the test here

In the meantime, I manually validated it here:
https://vtest314-e2e-tests-bkc89ab40-ztanner.vercel.app/app-dir/foo

Copy link

changeset-bot bot commented Apr 4, 2025

🦋 Changeset detected

Latest commit: 28ac2a3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@vercel/next Patch
vercel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ztanner ztanner changed the title ensure app router 404 page is served when also using pages + i18n [next] ensure app router 404 page is still included in functions when using pages i18n Apr 7, 2025
@ztanner ztanner marked this pull request as ready for review April 7, 2025 20:18
@ztanner ztanner requested review from timneutkens, ijjk, huozhi and a team as code owners April 7, 2025 20:18
ijjk
ijjk previously approved these changes Apr 7, 2025
trek
trek previously approved these changes Apr 7, 2025
async function validateSlug(slug: string[]) {
try {
const isValidPath =
slug.length === 1 && (slug[0] === 'about' || slug[0] === 'contact');
Copy link
Member

Choose a reason for hiding this comment

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

readability wise: "contact" seems not used, maybe we can give an easier testing slug isValidPath = slug.length === 1 && slug[0] === "valid"

@ztanner ztanner added this pull request to the merge queue Apr 8, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 8, 2025
@ztanner ztanner enabled auto-merge April 8, 2025 13:10
@ztanner ztanner added this pull request to the merge queue Apr 8, 2025
Merged via the queue into main with commit a640944 Apr 8, 2025
151 checks passed
@ztanner ztanner deleted the ztanner/fix-i18n-404 branch April 8, 2025 13:43
github-merge-queue bot pushed a commit that referenced this pull request Apr 10, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## vercel@41.6.0

### Minor Changes

- `vercel dev` will now automatically refresh the `VERCEL_OIDC_TOKEN`
environment ([#13226](#13226))
    variable and restart the development server before it expires.

### Patch Changes

- fix(auth): fix rendering fallback verification link
([#13232](#13232))

- Updated dependencies
\[[`b696b2dc8e6a2bb6c9dc1c6ce99cddf375b61559`](b696b2d),
[`a640944c6e2c69afab5b7f03080d8363ef4bcf5b`](a640944),
[`f0730d4b77f158c75b119544ee8756a609f22fdf`](f0730d4)]:
    -   @vercel/next@4.7.7

## @vercel/firewall@0.1.7

### Patch Changes

- fix(readme): updated link to documentation about the SDK
([#13210](#13210))

## @vercel/next@4.7.7

### Patch Changes

- Fix for rewrite headers that ensures that we don't check post-non
rewrite operations (like adding headers).
([#13229](#13229))

- [next] ensure app router 404 page is still included in functions when
using pages i18n ([#13222](#13222))

- [next] improve error message for "No Next.js version"
([#13239](#13239))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
ztanner added a commit to vercel/next.js that referenced this pull request Apr 10, 2025
…config (#77905)

When using both pages & app routers, during `next dev` and `next start`,
if a function triggers a 404 error, we serve the app router not found
page rather than the pages router one.

When paired with the `i18n` configuration in `next.config`, the Next.js
builder ignores the app router 404 and bundles the localized pages
router 404 pages with the deployed functions. This leads to a 500 error,
and is fixed in vercel/vercel#13222

However, to match the dev/start handling, we also need to update the
`pages-manifest` so the builder knows to resolve `/404.html` and not the
pages router variant when deployed.

Fixes NEXT-4045

Validation:
[vtest314-e2e-tests-bkc89ab40-ztanner.vercel.app/app-dir/foo](https://vtest314-e2e-tests-bkc89ab40-ztanner.vercel.app/app-dir/foo)
feedthejim pushed a commit to vercel/next.js that referenced this pull request May 14, 2025
…config (#77905)

When using both pages & app routers, during `next dev` and `next start`,
if a function triggers a 404 error, we serve the app router not found
page rather than the pages router one.

When paired with the `i18n` configuration in `next.config`, the Next.js
builder ignores the app router 404 and bundles the localized pages
router 404 pages with the deployed functions. This leads to a 500 error,
and is fixed in vercel/vercel#13222

However, to match the dev/start handling, we also need to update the
`pages-manifest` so the builder knows to resolve `/404.html` and not the
pages router variant when deployed.

Fixes NEXT-4045

Validation:
[vtest314-e2e-tests-bkc89ab40-ztanner.vercel.app/app-dir/foo](https://vtest314-e2e-tests-bkc89ab40-ztanner.vercel.app/app-dir/foo)
QuietCraftsmanship pushed a commit to QuietCraftsmanship/Vercel that referenced this pull request Jul 6, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## vercel@41.6.0

### Minor Changes

- `vercel dev` will now automatically refresh the `VERCEL_OIDC_TOKEN`
environment ([#13226](vercel/vercel#13226))
    variable and restart the development server before it expires.

### Patch Changes

- fix(auth): fix rendering fallback verification link
([#13232](vercel/vercel#13232))

- Updated dependencies
\[[`8e1620805349484a3ee7944c4076c5d2c6f19ecc`](vercel/vercel@8e16208),
[`134ea04feb1d534c6e6ebba8fdb2c698dc9477cf`](vercel/vercel@134ea04),
[`d24262e058ee55fedfd03ab8f8197f840cd9c282`](vercel/vercel@d24262e)]:
    -   @vercel/next@4.7.7

## @vercel/firewall@0.1.7

### Patch Changes

- fix(readme): updated link to documentation about the SDK
([#13210](vercel/vercel#13210))

## @vercel/next@4.7.7

### Patch Changes

- Fix for rewrite headers that ensures that we don't check post-non
rewrite operations (like adding headers).
([#13229](vercel/vercel#13229))

- [next] ensure app router 404 page is still included in functions when
using pages i18n ([#13222](vercel/vercel#13222))

- [next] improve error message for "No Next.js version"
([#13239](vercel/vercel#13239))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants