Repository navigation
fix(dev): scan pages/ for client and ssr deps when app/ also exists - #4613
Conversation
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
|
/bigbonk review for issues |
@vinext/cloudflare
create-vinext-app
@vinext/types
vinext
@cloudflare/workers-response-store
commit: |
|
|
||
| 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!; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
|
Review: 1 findings. Posted 1 actionable inline comment. Targeted tests passed. |
|
Performance benchmarksCompared 0 improved · 0 regressed · 7 within ±1.5%
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.
|
/bigbonk review for issues |
|
LGTM! |
Wrangler writes local state into the project during dev, and other parallel tests copy cf-app-basic.
|
/bigbonk review for issues |
|
LGTM! |
There was a problem hiding this comment.
✅ 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
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>
Fixes #4592
Problem
When a project has both
app/andpages/, dev seeds every dependency optimizer (rsc, ssr, client) with onlyapp/**/*.{tsx,ts,jsx,js}plus the instrumentation files.pages/**is only scanned when there is noapp/. So a dependency that only Pages Router pages or_appimport 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, addpages/**/*.{tsx,ts,jsx,js}to thessrandclientoptimizer entries. These are the environments that load Pages Router modules:ssr;loadModule("ssr", …);vinext-client-entryinclient.rscnever loads Pages modules, so its entries are unchanged.The glob is the same one the Pages-only path already uses, including
_documentandpages/api. The hybrid client already crawlsapp/**route handlers and excludes thenext/*shims andserverExternalPackages.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
pages-only-dependencyincf-app-basic's trackednode_modules, following themodule-identity-dependencypattern. Onlypages/pages-only-dependency.tsximports it.tests/dep-scan-bundled-deps.test.ts, new "hybrid dependency scan" test:cf-app-basic's dev server from the dist build.clientandssroptimizers discoverpages-only-dependencyat startup.ssrenvironment runs discovery; Node dev's server optimizers have discovery off.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 theapp-basic(Node hybrid) server:pages/**is in thessrandcliententries and not inrsc.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 ofcf-app-basicwith the new page.vp checkon 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):/aboutresponseThe difference is within noise. Builds are unaffected, because
optimizeDeps.entriesonly drives the dev optimizer.