Skip to content

fix: cloudflare + tanstack start + vite 6/7/8 compatibility#690

Merged
theoephraim merged 17 commits into
mainfrom
fix/latest-cf-tanstack
May 5, 2026
Merged

fix: cloudflare + tanstack start + vite 6/7/8 compatibility#690
theoephraim merged 17 commits into
mainfrom
fix/latest-cf-tanstack

Conversation

@theoephraim

Copy link
Copy Markdown
Member

Summary

Fixes compatibility issues with the varlock vite and cloudflare integrations across Vite 6, 7, and 8, particularly when used with TanStack Start.

Vite integration fixes

  • Duplicate SSR init injection: When TanStack Start + Cloudflare detect multiple entry modules in the same environment, init code was injected twice. Fixed with a dedup guard (build-mode only — dev mode needs re-injection after dep re-optimization).
  • Vite 6 isEntry crash: Accessing getModuleInfo(id).isEntry in Vite 6 dev mode throws instead of returning false. Wrapped in try/catch with fallback to moduleIds[0].
  • Dep optimizer breaking varlock/env: In Cloudflare worker environments, the dep optimizer would pre-bundle varlock/env and then lose the file after re-optimization. Fixed by excluding varlock packages from optimizeDeps via configEnvironment (Vite 7+) and configResolved (Vite 6 fallback).

Cloudflare integration fixes

  • Preview env injection: Added FIFO-based env injection for vite preview so initVarlockEnv can find env vars in miniflare. Secrets never touch disk on Unix (FIFO named pipe); Windows falls back to a temp file.

Test coverage

  • Split vite framework tests by version (v5, v6, v7, v8)
  • Split cloudflare framework tests by version (v6, v7, v8)
  • Added TanStack Start framework tests covering both node and cloudflare targets across Vite 6, 7, and 8
  • Registered tanstack-start in CI integration detection

Test plan

  • All 311 framework tests pass locally (vite 4×51 + cloudflare 3×13 + wrangler 23 + tanstack 3×15)
  • CI framework tests pass

- Fix duplicate SSR init injection when TanStack Start + Cloudflare
  detect multiple entry modules in the same environment (dedup via
  Set keyed by environment name, build-mode only)
- Fix Vite 6 dev mode crash: `isEntry` property throws in dev,
  wrapped in try/catch with fallback to moduleIds[0]
- Fix Vite dep optimizer breaking varlock/env in CF worker
  environments: exclude varlock packages from optimizeDeps via
  configEnvironment (Vite 7+) and configResolved (Vite 6 fallback)
- Add preview env injection for CF builds via FIFO named pipe so
  secrets never touch disk (Windows falls back to temp file)
- Split vite and cloudflare framework tests by version (v5-v8)
- Add TanStack Start framework tests (node + cloudflare, vite 6/7/8)
- Register tanstack-start in CI integration detection
@theoephraim theoephraim added the framework-tests Trigger framework integration tests on PR label May 4, 2026
@github-actions

github-actions Bot commented May 4, 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.0.1 → 1.0.2 (cascade)
  • @varlock/cloudflare-integration 1.1.0 → 1.1.1
  • @varlock/vite-integration 1.1.0 → 1.1.1

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 May 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 874e586

Verifies ENV.x works at module top-level (not just inside handlers)
for both node and cloudflare targets across vite 6/7/8.
Adds ENV.x access at module evaluation time (outside fetch handler)
to the basic worker. This currently fails because initVarlockEnv()
runs after the worker module body in the bundled output.
Replaces inline init code injection with a virtual module import
(`\0varlock-ssr-init`). The virtual module has no transitive
dependencies on user code, so the bundler evaluates it first in the
concatenated output — ensuring initVarlockEnv() runs before any
user modules that access ENV at the top level.

Previously, init code was appended to the entry module's body, which
ran last in the bundle after all statically-imported user modules
had already been evaluated.
The virtual module approach makes dedup unnecessary — ES modules
evaluate only once regardless of how many entries import them.
Throw a clear error if a .dev.vars file exists at the project root
(during dev/build) or in the build output (during preview), since it
conflicts with varlock's automatic env injection.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 5, 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 e5f658c Commit Preview URL

Branch Preview URL
May 05 2026, 05:30 PM

@theoephraim theoephraim merged commit 1935514 into main May 5, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant