Skip to content

fix(constants): guard Node feature detection in browser imports - #3394

Merged
james-elicx merged 1 commit into
cloudflare:mainfrom
camc314:codex/fix-browser-constants
Sep 23, 2026
Merged

james-elicx merged 1 commit into
cloudflare:mainfrom
camc314:codex/fix-browser-constants

Conversation

@camc314

@camc314 camc314 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor
  • Importing next/constants in a browser throws before hydration because optional chaining on process?.features still requires process to be declared. Guard the feature check with typeof process so runtimes without that global retain the standard config extensions while Node preserves its existing behavior.
  • Adds a regression that builds the constants shim for browsers and evaluates it in a fresh VM without process. The failure surfaced in the upstream cache-components server-action suite.
  • The source commit records all 3 upstream tests passing (previously 2/3), 1,315 shim and browser-constants tests passing, and passing targeted checks and package build.

Importing next/constants in a browser evaluated process?.features even when
process was undeclared. Optional chaining does not protect an undeclared root
identifier, so the generated client bundle threw before hydration and the
upstream cache-components action form stayed at its initial value.

Check typeof process before reading Node's optional TypeScript feature flag.
Node keeps the existing CONFIG_FILES values; browsers and Edge runtimes
without process safely retain the standard config extensions.

Add a real browser-target constants bundle regression evaluated in a fresh VM
without process. It fails with ReferenceError before the guard and passes now.

Validation:
- Original v16.2.6 cache-components.server-action suite: 3/3 passed, compared
  with 2/3 before this fix, without changing the upstream test or fixture.
- Complete shims and browser-constants tests: 1315 passed.
- Targeted vp check and vinext package build pass.
Copilot AI lite review requested due to automatic review settings September 22, 2026 18:44

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pkg-pr-new

pkg-pr-new Bot commented Sep 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vinext/cloudflare

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

create-vinext-app

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

@vinext/types

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

vinext

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

@cloudflare/workers-response-store

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

commit: f3e29bf

@github-actions

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared f3e29bf against base 087f8d6 using alternating same-runner rounds. Next.js was unchanged and skipped.

1 improved · 0 regressed · 5 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 142.3 KB 142.3 KB ⚫ +0.0%
Client entry size (gzip) vinext 129.7 KB 129.7 KB ⚫ 0.0%
Dev server cold start vinext 3.38 s 3.32 s 🟢 -1.8%
Production build time vinext 3.90 s 3.87 s ⚫ -0.9%
RSC entry closure size (gzip) vinext 127.9 KB 127.9 KB ⚫ +0.0%
Server bundle size (gzip) vinext 226.0 KB 226.0 KB ⚫ +0.0%

View detailed results and traces

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

@james-elicx

Copy link
Copy Markdown
Member

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

@james-elicx
james-elicx merged commit 182f1d9 into cloudflare:main Sep 23, 2026
66 checks passed
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.

3 participants