AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack Dev Server Intermittently 404S Child Routes Below Dynamic Segments Inside Route Groups Due To Route-Tree Race

Next.js dev server (Turbopack) fails to match routes that are children of a dynamic segment nested inside route groups, returning instant 404 for the entire session. The issue is probabilistic, occurs under module graph load, and is repaired by any file event under app/. Production builds are unaffected.

highConfidence 85%Next.jsAffected V16.3.1Affected V16.3.2Affected V16.4.0-Canary.7

Origin Analysis

A race condition in Turbopack's route-tree construction causes child routes under dynamic segments within route groups to be omitted from the route matcher during initial dev server startup. The dynamic leaf itself matches, but its nested children do not, indicating incomplete registration of nested route entries. The race is timing-dependent and can be triggered by CPU load or large module graphs.
1. Clone https://github.com/arpi09/next-dev-router-group-race; 2. cd next-dev-router-group-race && npm install; 3. (Optional) node scripts/cpu-load.mjs 4 30 to increase reproduction rate; 4. node scripts/boot-loop.mjs 10 to classify boots; 5. Manual check: npx next dev -p 4321; curl -i http://localhost:4321/fam1/a/child -> instant 404 with no 'Compiling /fam1/[slug]/child' log; curl -i http://localhost:4321/fam1/a -> 200; Append a blank line to any app/**/page.js, save, remove, save; curl again -> compiles and returns 200.

Fixing Code Block

Edge Case Audit

This workaround modifies a file in app/, which could interfere with active editors, trigger unnecessary hot reloads, or fail if the file is read-only or deleted. It should be disabled once the underlying Next.js bug is fixed; rollback by removing the wrapper script and starting `next dev` normally. In multi-process or concurrent dev environments, ensure the TOUCH_FILE path is correct and the script does not run multiple times on the same file simultaneously. The script also assumes CommonJS require and may need adjustment for ESM projects.

Ecosystem Topology