Unverified Commit ae0e0a50 authored by Marcos Hernanz's avatar Marcos Hernanz Committed by GitHub

Turbopack: remove stale manifests for deleted routes (#97333)

## What?

- remove manifest fragments when Turbopack's development entrypoint
cleanup removes a deleted page
- add an end-to-end regression for replacing concrete App Router pages
with an optional catch-all without restarting the dev server

## Why?

Turbopack already removes deleted entry keys from its asset mapper,
subscriptions, issues, and client state. It did not remove the
corresponding records from `TurbopackManifestLoader`, so the next
manifest write continued to serialize deleted App Router routes.

When a deleted concrete route is replaced by an optional catch-all,
those stale records conflict with the new route at the same specificity.
The dev server reports the route conflict and responds with 404 until it
is restarted.

This is independently consistent with the cleanup identified in #97194.
This draft adds end-to-end coverage that fails on current canary by
observing both the 404 and stale manifest records, then passes with the
lifecycle fix.

## How?

Pass the existing manifest loader to `handleEntrypointsDevCleanup` and
call its existing `delete(key)` method in the same branch that deletes
the stale asset mapping. This keeps all per-entry manifest maps
synchronized with the authoritative current entrypoint set without
special-casing any route shape.

The regression test:

1. compiles two concrete localized routes
2. deletes both pages and adds an optional catch-all
3. waits for three affected paths to return the new catch-all content
4. verifies the development app-paths manifest contains the catch-all
and no deleted entries

## Verification

- reproduced the report on `16.3.1-canary.10`: all four reported paths
returned 404 after the live route replacement and returned 200 after a
restart
- confirmed the regression fails on current canary before the source
change with the same-specificity route error and a 404 response
- `pnpm test-dev-turbo
test/development/app-dir/hmr-deleted-page/hmr-deleted-page.test.ts`
- `pnpm test-dev-webpack
test/development/app-dir/hmr-deleted-page/hmr-deleted-page.test.ts`
- `pnpm test-dev-rspack
test/development/app-dir/hmr-deleted-page/hmr-deleted-page.test.ts`
- `CI=1 pnpm build-all`
- `pnpm --filter=next build`
- formatting, ESLint, staged-diff, and signed-commit checks

Fixes #97035
parent 1173626d
......@@ -680,6 +680,7 @@ export async function handleEntrypoints({
await handleEntrypointsDevCleanup({
currentEntryIssues,
currentEntrypoints,
manifestLoader,
...dev,
})
......@@ -844,6 +845,7 @@ export async function handleEntrypoints({
async function handleEntrypointsDevCleanup({
currentEntryIssues,
currentEntrypoints,
manifestLoader,
assetMapper,
changeSubscriptions,
......@@ -854,11 +856,13 @@ async function handleEntrypointsDevCleanup({
}: {
currentEntrypoints: Entrypoints
currentEntryIssues: EntryIssuesMap
manifestLoader: TurbopackManifestLoader
} & HandleEntrypointsDevOpts) {
// this needs to be first as `hasEntrypointForKey` uses the `assetMapper`
for (const key of assetMapper.keys()) {
if (!hasEntrypointForKey(currentEntrypoints, key, assetMapper)) {
assetMapper.delete(key)
manifestLoader.delete(key)
}
}
......
export default function ProjectHomePage() {
return <main>old localized home route</main>
}
export default function ProjectPage() {
return <main>old localized project route</main>
}
import { join } from 'path'
import { nextTestSetup, FileRef } from 'e2e-utils'
import { waitForRedbox, waitForNoRedbox } from 'next-test-utils'
import { retry, waitForRedbox, waitForNoRedbox } from 'next-test-utils'
import { waitForHydration } from 'development-sandbox'
describe('hmr-deleted-page', () => {
......@@ -27,4 +27,57 @@ describe('hmr-deleted-page', () => {
await waitForNoRedbox(browser)
expect(await browser.elementByCss('h1').text()).toBe('404')
})
it('should discard manifests for deleted pages', async () => {
expect(await next.render('/en/project')).toContain(
'old localized project route'
)
expect(await next.render('/en/project/acme/home')).toContain(
'old localized home route'
)
const initialAppPathsManifest = JSON.parse(
await next.readFile('.next/dev/server/app-paths-manifest.json')
)
expect(initialAppPathsManifest['/[locale]/project/page']).toBe(
'app/[locale]/project/page.js'
)
expect(
initialAppPathsManifest['/[locale]/project/[projectId]/home/page']
).toBe('app/[locale]/project/[projectId]/home/page.js')
await next.deleteFile('app/[locale]/project/page.tsx')
await next.deleteFile('app/[locale]/project/[projectId]/home/page.tsx')
await next.patchFile(
'app/[locale]/project/[[...slug]]/page.tsx',
`export default function ProjectCatchAllPage() {
return <main>new localized project catch-all</main>
}`
)
await retry(async () => {
for (const pathname of [
'/en/project',
'/en/project/acme/home',
'/en/project/acme/schedule',
]) {
const response = await next.fetch(pathname)
expect(response.status).toBe(200)
expect(await response.text()).toContain(
'new localized project catch-all'
)
}
const appPathsManifest = JSON.parse(
await next.readFile('.next/dev/server/app-paths-manifest.json')
)
expect(appPathsManifest['/[locale]/project/[[...slug]]/page']).toBe(
'app/[locale]/project/[[...slug]]/page.js'
)
expect(appPathsManifest['/[locale]/project/page']).toBeUndefined()
expect(
appPathsManifest['/[locale]/project/[projectId]/home/page']
).toBeUndefined()
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment