Skip to content

Cloudflare: clear error for a missing __VARLOCK_ENV binding, redact RSC dev console replay, vinext guide - #1236

Merged
theoephraim merged 9 commits into
mainfrom
vite-rsc-console-replay-redaction
Oct 19, 2026
Merged

theoephraim merged 9 commits into
mainfrom
vite-rsc-console-replay-redaction

Conversation

@theoephraim

@theoephraim theoephraim commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Fallout from #1234 (vinext + @varlock/cloudflare-integration) and from building a vinext example.

Missing __VARLOCK_ENV binding now fails with a usable message

The built Worker only gets its env from the __VARLOCK_ENV binding. Running the build output under plain wrangler dev, or deploying it with plain wrangler deploy or a tool that drives wrangler itself (vinext-cloudflare deploy), leaves it out, and the Worker died in initVarlockEnv with advice (auto-load, varlock run) that cannot apply inside workerd. The injected Cloudflare entry code now throws a specific error: run and deploy the build output through varlock's wrappers, with a link to the Cloudflare docs page, whose troubleshooting entry lists the commands. The string stays tool-agnostic on purpose, since cf CLI support is coming and bundles already installed cannot be updated; the docs can. Verified on the issue's repro: stock wrangler dev shows the new error, varlock-wrangler dev --config dist/server/wrangler.json serves the page.

Fixes #1234

Secrets logged in Server Components leaked into the dev RSC payload

React's dev-only react-server-dom-*-server.*.development.js wraps every console method when it loads and serializes the original call args into the flight stream (so server logs show in browser devtools). It loads after the varlock init module, so its wrapper sat outside our redacting one: console.log(ENV.SECRET) in a Server Component put the raw value into the inlined RSC payload, response leak detection then caught it and truncated the page (1.4KB instead of 15KB under vinext dev).

The vite integration's transform now inserts a console re-patch right after the statement that installs React's wrapper, inside React's module body, putting our wrapper back on the outside, the same thing the Next.js integration already does via its loader. Placing it inside the body (not at the end of the module) matters in dev, where the dep optimizer wraps the body in a lazy require_* factory in a shared chunk that only runs when some entry calls it. The init module exposes globalThis.__varlockPatchConsole, matching the init-server/init-edge bundles. Tests evaluate the transformed code and check the replay wrapper gets redacted args, in the direct and shared-factory shapes.

Docs

  • new /integrations/vinext/ guide: setup, the start/deploy script swap, why vinext-cloudflare deploy cannot be used, boot errors; listed in the sidebar and the integrations overview
  • Cloudflare page links to it and gains a troubleshooting entry; Next.js page points vinext users at it

Example project: dmno-dev/varlock-examples integrations/vinext (separate PR).

React's dev-only react-server-dom server build wraps every console method
when it loads and serializes the original call args into the RSC flight
stream. It loads after the varlock init module, so its wrapper sat outside
ours and saw raw values: logging a sensitive item in a Server Component put
the secret into the inlined flight payload, where response leak detection
caught it and truncated the page.

Re-patch the console right after that module evaluates, so our redacting
wrapper is on the outside again, matching what the Next.js integration does
in every server file. In dev the body lives in a lazily invoked factory in
a shared pre-bundled chunk, so the dep entry that calls it is matched too.

Also document using varlockCloudflareVitePlugin with vinext.
Running the build output under plain wrangler dev, or deploying it with plain
wrangler deploy or a tool that drives wrangler itself (vinext-cloudflare
deploy), leaves the Worker without the binding. It then died in
initVarlockEnv with advice (auto-load, varlock run) that cannot apply inside
workerd. The injected entry code now throws a Cloudflare-specific error
pointing at varlock-wrangler dev / deploy with the same --config.

Docs: vinext start/deploy script swap and a troubleshooting entry.

Closes #1234
Setup with varlockCloudflareVitePlugin, the start/deploy script swap to
varlock-wrangler against dist/server/wrangler.json, why vinext-cloudflare
deploy cannot be used, and the boot errors to expect. Cloudflare and
Next.js pages link to it.
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

bumpy-frog

The changes in this PR will be included in the next version bump.

patch Patch releases

  • @varlock/astro-integration 1.4.4 → 1.4.5 (cascade)
  • @varlock/cloudflare-integration 1.6.2 → 1.6.3
  • @varlock/nuxt-integration 0.1.4 → 0.1.5 (cascade)
  • @varlock/vite-integration 1.5.4 → 1.5.5

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@pkg-pr-new

pkg-pr-new Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

varlock

npm i https://pkg.pr.new/varlock@1236

@varlock/astro-integration

npm i https://pkg.pr.new/@varlock/astro-integration@1236

@varlock/cloudflare-integration

npm i https://pkg.pr.new/@varlock/cloudflare-integration@1236

@varlock/nuxt-integration

npm i https://pkg.pr.new/@varlock/nuxt-integration@1236

@varlock/vite-integration

npm i https://pkg.pr.new/@varlock/vite-integration@1236

@varlock/native-helper-darwin

npm i https://pkg.pr.new/@varlock/native-helper-darwin@1236

@varlock/native-helper-linux-arm64

npm i https://pkg.pr.new/@varlock/native-helper-linux-arm64@1236

@varlock/native-helper-linux-x64

npm i https://pkg.pr.new/@varlock/native-helper-linux-x64@1236

@varlock/native-helper-win32-x64

npm i https://pkg.pr.new/@varlock/native-helper-win32-x64@1236

commit: beca468

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
varlock-website beca468 Commit Preview URL

Branch Preview URL
Oct 19 2026, 05:21 AM

@pullfrog pullfrog Bot 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.

Important

The RSC re-patch still runs too early in a shared lazy-factory optimizer topology, leaving the dev console replay fix incomplete.

Reviewed changes: Reviewed the Cloudflare startup diagnostic, Vite RSC console re-patching, associated tests, and vinext documentation.

  • Worker startup: Missing runtime bindings now produce actionable varlock-wrangler guidance.
  • RSC console replay: SSR init exposes a global console patch, and matching React dev modules receive an appended re-patch.
  • Vinext setup: A new guide covers the legacy Wrangler integration, script replacements, env access, and troubleshooting.
  • Verification: Integration builds passed, along with all 18 Vite and 50 Cloudflare unit tests; a full vinext request and website build were not run.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment thread packages/integrations/vite/src/index.ts Resolved
Review caught a topology the previous placement missed: when another
optimized dependency also requires server.edge, the dep optimizer moves the
require_server_edge factory into a shared chunk. That chunk matched and ran
the appended re-patch while only defining the factory, and the facade that
later calls it did not match, so React's wrapper went back outside ours.

Insert the re-patch right after the statement that installs React's wrapper
instead. It then runs whenever that body executes, whatever chunk or lazy
factory it lives in. The tests now evaluate the transformed code and assert
the replay wrapper receives redacted args, in both the direct and the
shared-factory shapes.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes: Reviewed the console replay ordering fix and regression tests added since the prior review.

  • Moved the re-patch: Inserted console redaction immediately after React installs its replay wrapper, inside the module body so shared lazy factories preserve the correct execution order.
  • Added execution coverage: Verified replay receives redacted arguments after both direct module evaluation and a delayed shared-factory invocation.
  • Verified the update: Built the Vite integration and its prerequisites; all 19 Vite tests passed. A full vinext request was not exercised.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

cf CLI support is coming, so naming varlock-wrangler in a string baked into
every bundle would go stale on installed versions. The error now says the
build output must be run and deployed through varlock's wrappers and links
a stable troubleshooting anchor, where the per-tool commands live.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes: Reviewed the startup diagnostic and documentation changes since the prior Pullfrog review.

  • Generalized the diagnostic: Replaced hardcoded wrapper commands with tool-agnostic guidance and a link to the Cloudflare documentation page.
  • Updated troubleshooting: Kept concrete varlock-wrangler commands in the docs, clarified the unsupported cf CLI, and removed the heading-specific link.
  • Verified the diagnostic: Passed all five Cloudflare binding-loader tests. A website build and full vinext request were not run.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

The RSC console replay re-patch looks for globalThis.__varlockPatchConsole,
which the init module only set on the init-only/resolved-env path. With
ssrInjectMode: 'auto-load' the re-patch was a no-op, leaving React's replay
wrapper outside varlock's redaction as before.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes: Reviewed the auto-load console re-patch exposure added since the prior Pullfrog review.

  • Exposed the re-patch function: Added globalThis.__varlockPatchConsole in auto-load mode so the RSC transform can restore outer console redaction after React installs its replay wrapper.
  • Extended mode coverage: Checked global exposure for both ordinary and preserved side-effect imports. The Vite integration and its prerequisites built successfully, and all 19 Vite tests passed; generated auto-load module execution and a full vinext request were not exercised.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

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.

Cloudflare integration + vinext 1.2: built worker crashes at boot (initVarlockEnv failed)

1 participant