Skip to content

fix(pages-router): only exclude top-level pages/api from page routing#3

Open
JaredStowell wants to merge 1 commit intomainfrom
codex/fix-pages-router-nested-api-exclusion
Open

fix(pages-router): only exclude top-level pages/api from page routing#3
JaredStowell wants to merge 1 commit intomainfrom
codex/fix-pages-router-nested-api-exclusion

Conversation

@JaredStowell
Copy link
Owner

Motivation

  • A recent change used the function-form glob exclude predicate which compared basenames and unintentionally excluded any directory named api at any depth, dropping valid nested page routes like pages/blog/api/index.tsx.
  • The function-form exclude was necessary for Node < 22.14 compatibility, so the fix must preserve that compatibility while restoring correct route discovery.

Description

  • Adjusted the scanPageRoutes glob usage to only exclude files/dirs that start with _ via the function-form predicate, removing the blanket name === "api" check.
  • Added an explicit runtime check to skip only top-level pages/api/* entries (if (file === 'api' || file.startsWith( api${path.sep})) continue;) so nested */api/* directories remain discoverable.
  • Added a fixture tests/fixtures/pages-basic/pages/blog/api/index.tsx and a test assertion in tests/routing.test.ts to cover discovery of nested api directories.
  • Files modified: packages/vinext/src/routing/pages-router.ts, tests/routing.test.ts, and the new fixture file under tests/fixtures/pages-basic/pages/blog/api/index.tsx.

Testing

  • Ran the targeted routing tests with npx vitest run tests/routing.test.ts, which passed: 1 test file, 61 tests, 61 passed.
  • The change is focused and validated by the added fixture and test; broader test suites (full Vitest / Playwright) are left to CI.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant