next.js
7b7cee30 - Error when app pages do not match any route (#97401)

Commit
80 days ago
Error when app pages do not match any route (#97401) ## What? This reports an error under `experimental.strictRouteMatching` when a `page.tsx` is left out of every retained matcher. A page can lose its own broad catchall matcher and still be valid if it participates in a more specific matcher, so this checks the final matcher set instead of treating every pruned candidate as an error. Both Webpack and Turbopack report every unmatched page in development and production builds. ## Why? Pages that are never selected by any complete loader tree are unreachable by construction. This usually means parallel slots define incompatible paths without matching pages or defaults, and silently ignoring those files makes the project look like it has routes that cannot actually exist. For example: ```text app/disagreeing-slots/ ├── layout.tsx ├── @first/foo/page.tsx ├── @second/bar/page.tsx └── [...slug]/page.tsx ``` Every candidate is incomplete: `/foo` has no match in `@second`, `/bar` has no match in `@first`, and URLs handled only by the catchall have no matching page or applicable default in either named slot. Strict route matching prunes all three matchers, and this change reports all three page files instead of silently leaving them out of the build. The same validation catches a real `children` branch that only becomes incomplete below its page: ```text app/declared-children/ ├── layout.tsx ├── page.tsx └── @panel/ ├── default.tsx └── details/page.tsx ``` `/declared-children` is valid, but `/declared-children/details` only has a page in `@panel`. Because the declared `children` slot has no matching page or default at `/details`, that matcher is pruned and `@panel/details/page.tsx` is reported as unreachable. The root `page.tsx` is still part of the valid `/declared-children` matcher and is not reported. A pruned matcher is not automatically an error. If `@slot/[...parts]/page.tsx` is combined into retained `/foo` and `/bar` matchers, that page still participates in routes and remains valid. ## How? Webpack snapshots the authored app page paths before pruning and compares them with the pages used by the retained app paths. Turbopack collects authored page source files from the directory tree and compares them with the files referenced by the final accepted loader trees. The tests cover disagreeing named slots, declared `children`, optional catchalls, route groups, nested slots, and the valid case where a pruned catchall is still used by more specific matchers. ## Verification - `pnpm test-start-turbo test/e2e/app-dir/unmatched-app-pages/unmatched-app-pages.test.ts` - `pnpm test-start-webpack test/e2e/app-dir/unmatched-app-pages/unmatched-app-pages.test.ts` - `pnpm test-dev-turbo test/e2e/app-dir/unmatched-app-pages/unmatched-app-pages.test.ts` - `pnpm test-dev-webpack test/e2e/app-dir/unmatched-app-pages/unmatched-app-pages.test.ts` - `pnpm test-start-turbo test/e2e/app-dir/parallel-routes-pruned-matchers/parallel-routes-pruned-matchers.test.ts` - `pnpm test-start-webpack test/e2e/app-dir/parallel-routes-pruned-matchers/parallel-routes-pruned-matchers.test.ts` <!-- NEXT_JS_LLM -->
Author
Parents
Loading