Skip to content

fix(dev): scan pages/ for client and ssr deps when app/ also exists - #4613

Merged
james-elicx merged 3 commits into
mainfrom
claude/fix-4592-dual-router-dep-scan
Nov 9, 2026
Merged

james-elicx merged 3 commits into
mainfrom
claude/fix-4592-dual-router-dep-scan

Conversation

@james-elicx

@james-elicx james-elicx commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes #4592

Problem

When a project has both app/ and pages/, dev seeds every dependency optimizer (rsc, ssr, client) with only app/**/*.{tsx,ts,jsx,js} plus the instrumentation files. pages/** is only scanned when there is no app/. So a dependency that only Pages Router pages or _app import is found on the first request for its page. Vite then re-optimizes and reloads the browser, and the reload cuts off whatever page load was in progress.

Fix

In the hybrid branch of vinext:config, add pages/**/*.{tsx,ts,jsx,js} to the ssr and client optimizer entries. These are the environments that load Pages Router modules:

  • the Node dev Pages runner uses ssr;
  • on Cloudflare and Nitro, the RSC entry reaches Pages through loadModule("ssr", …);
  • the browser loads vinext-client-entry in client.

rsc never loads Pages modules, so its entries are unchanged.

The glob is the same one the Pages-only path already uses, including _document and pages/api. The hybrid client already crawls app/** route handlers and excludes the next/* shims and serverExternalPackages.

Next.js has no dependency pre-bundler and compiles Pages Router pages on demand without a full reload. This change makes vinext's hybrid dev match that.

Tests

  • New checked-in package pages-only-dependency in cf-app-basic's tracked node_modules, following the module-identity-dependency pattern. Only pages/pages-only-dependency.tsx imports it.
  • tests/dep-scan-bundled-deps.test.ts, new "hybrid dependency scan" test:
    • Starts cf-app-basic's dev server from the dist build.
    • Asserts that both the client and ssr optimizers discover pages-only-dependency at startup.
    • Pre-fix, neither does.
    • Cloudflare is used because its Worker ssr environment runs discovery; Node dev's server optimizers have discovery off.
    • It doesn't assert on rsc. There, the scan already reaches pages through the Worker entry into vinext's Pages server entry, before and after this change.
  • tests/app-router-dev-server.test.ts, extended entries test on the app-basic (Node hybrid) server:
    • pages/** is in the ssr and client entries and not in rsc.
    • It fails pre-fix.

Validation

  • vp test run tests/dep-scan-bundled-deps.test.ts tests/app-router-dev-server.test.ts: 247/247 pass. With the pre-fix dist and source, the new and extended assertions fail.
  • vp test run tests/prerender.test.ts tests/connection-probe-worker.test.ts: pass. These are Cloudflare builds of cf-app-basic with the new page.
  • vp check on the changed files: pass.

Performance

Dev cold start on tests/fixtures/app-basic, 7 alternating runs of main vs this branch, with a fresh dep cache each run (median):

main branch
client dep scan done 623 ms 635 ms
first /about response 4313 ms 4269 ms

The difference is within noise. Builds are unaffected, because optimizeDeps.entries only drives the dev optimizer.

With both routers, the dev optimizers only used app/** as entries, so a
dependency that only Pages Router pages or _app import was discovered on the
first request for its page, re-optimizing deps and reloading the browser.
Add pages/** to the ssr and client entries, the environments that render and
hydrate Pages Router modules. rsc never loads them.

Fixes #4592
@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 4f28f0d132d515a2c4e3eafbfc5d3c2b9bf578e2 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@pkg-pr-new

pkg-pr-new Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vinext/cloudflare

npm i https://pkg.pr.new/@vinext/cloudflare@4613

create-vinext-app

npm i https://pkg.pr.new/create-vinext-app@4613

@vinext/types

npm i https://pkg.pr.new/@vinext/types@4613

vinext

npm i https://pkg.pr.new/vinext@4613

@cloudflare/workers-response-store

npm i https://pkg.pr.new/@cloudflare/workers-response-store@4613

commit: 562e0f3

Comment thread tests/app-router-dev-server.test.ts Outdated

it("discovers dependencies only Pages Router pages import at startup", async () => {
// Otherwise the first request for such a page re-optimizes and reloads.
const optimizer = server.environments.client.depsOptimizer!;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This behavior test only exercises the client optimizer, even though the fix also changes startup discovery for ssr. The config assertion above verifies that a glob is assigned, but an SSR-specific scan/resolution regression could still pass while Pages server dependencies remain lazily discovered. Please inspect both client and ssr optimizer metadata here (or add an equivalent SSR assertion).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 300bfd9: the behavior test now lives in tests/dep-scan-bundled-deps.test.ts and checks both the client and ssr optimizers on the Cloudflare hybrid fixture cf-app-basic. Node dev's server optimizers have Vite's dependency discovery off, so ssr discovery only applies where the Worker environments run it.

@ask-bonk

ask-bonk Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Review: 1 findings.

Posted 1 actionable inline comment. Targeted tests passed.

github run

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor
Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original
response-store-demo preview production
workers-cache preview production
kv preview production
static-assets-cache preview production
static-assets-pages preview production
static-assets-pages-i18n preview production
static-export preview production
web preview production

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 562e0f3 against base e7a12de using alternating same-runner rounds. Next.js was unchanged and skipped.

0 improved · 0 regressed · 7 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 153.5 KB 153.5 KB ⚫ +0.0%
Client entry size (gzip) vinext 141.6 KB 141.7 KB ⚫ +0.0%
Dev server cold start vinext 2.79 s 2.76 s ⚫ -1.1%
Dev server cold start (large Pages Router app) vinext 24.64 s 24.45 s ⚫ -0.8%
Production build time vinext 3.82 s 3.79 s ⚫ -0.7%
RSC entry closure size (gzip) vinext 141.5 KB 141.5 KB ⚫ -0.0%
Server bundle size (gzip) vinext 250.7 KB 250.6 KB ⚫ -0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

Move the startup discovery regression to cf-app-basic, where the Worker ssr
environment discovers dependencies, so it checks both environments that load
Pages Router modules. Node dev's ssr optimizer does not discover dependencies.
@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 300bfd9b76e51b5b83d4b9211710ce0dbf79ef22 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@ask-bonk

ask-bonk Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

Wrangler writes local state into the project during dev, and other parallel
tests copy cf-app-basic.
@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 562e0f306db033be0d1a1339e590f9440e5030c1 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@ask-bonk

ask-bonk Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

@james-elicx
james-elicx marked this pull request as ready for review November 9, 2026 01:02

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Approved — A small, focused fix to the dev optimizer entries in hybrid projects, with tests on both the Node and Cloudflare hybrid fixtures; no issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

The new ssrAndClientOptimizeEntries is only added when pages/ exists, uses the same glob as the Pages-only path, and is applied to exactly the ssr and client environments. The tests check both the configured entries and the startup discovery in both environments.


📝 Documentation: ✅ LGTM

The updated inline comments describe the new behavior correctly.


Reviewed commit: 562e0f30

@james-elicx
james-elicx merged commit 34aac08 into main Nov 9, 2026
107 checks passed
@james-elicx
james-elicx deleted the claude/fix-4592-dual-router-dep-scan branch November 9, 2026 10:55
@github-actions github-actions Bot mentioned this pull request Nov 9, 2026
MrIago added a commit to MrIago/vinext that referenced this pull request Nov 14, 2026
Brings in the 16 upstream commits up to cloudflare#4626. Where upstream fixed an
issue mriago/next already fixed, the official fix stays and ours goes:

- cloudflare#4612 (/404 in dev, cloudflare#4591): drops our dev-server /404 status and its
  test. Ours also answered 404 for /_next/data/.../404.json, which Next
  answers with 200.
- cloudflare#4611 (SIGTERM, cloudflare#4588): drops server/graceful-shutdown.ts, the
  gracefulShutdown option in cli.ts and standalone.ts, and its tests.
  closeServerOnTerminationSignals keeps NEXT_MANUAL_SIG_HANDLE and the
  130/143 exit codes, and also drains waitUntil work.
- cloudflare#4610 (next/head in the App Router, cloudflare#4589): drops head.react-server.ts,
  HeadManagerContext and its provider in app-route-tree.ts, the
  Pages-only resolveId exception and the fixture's legacy-head.tsx, with
  their tests. useIsAppRouterTree returns true in react-server, so a
  Server Component's <Head> no longer reaches useRef, and next/head
  keeps resolving to the full shim, so Pages-only Workers builds keep
  resetSSRHead and the rest of the exports.
- cloudflare#4613 (pages/ dep scan, cloudflare#4592): drops our client-only crawl and
  tests/optimize-deps-hybrid-pages.test.ts; upstream crawls pages/ in
  both ssr and client.
- cloudflare#4616 (invalid host / `//`, cloudflare#4600): drops our try in
  isReferencedAsset and its test.
- cloudflare#4607 and cloudflare#4606 (tests cloudflare#4585, cloudflare#4586): drops our NODE_PATH reset in
  deploy.test.ts and our realpath change in the action-owner e2e.

cloudflare#4617 moved the App Router navigation runtime to
shims/app-router-navigation.ts. Our changes to navigation.ts (static
shell prefetches, Partial Prefetching kinds, app-prefetch-setup
cancellation) move with it; only the useSearchParams shell hole stays in
navigation.ts. The non-reusable prefetch branch keeps cloudflare#4615's
sharedBehavior and overrides prefetchKind/prepareSnapshot for static
shells.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

With both routers, dev only scans app/ for client dependencies

1 participant