Skip to content

Add sandbox support to @cloudflare/vite-plugin#12794

Merged
edmundhung merged 2 commits intocloudflare:mainfrom
aron-cf:vite-plugin-sandboxes
Mar 12, 2026
Merged

Add sandbox support to @cloudflare/vite-plugin#12794
edmundhung merged 2 commits intocloudflare:mainfrom
aron-cf:vite-plugin-sandboxes

Conversation

@aron-cf
Copy link
Copy Markdown
Contributor

@aron-cf aron-cf commented Mar 6, 2026

This commit ensures that all websocket requests (including those that
use the vite-hmr protocol) are routed to the worker. This fixes a minor
issue where the plugin will drop HMR requests from sandbox preview URLs.

The handler now checks to see if the host matches the pattern used by
sandboxes. <port>-<sandbox_id>-<token>.localhost.

The URL provided to the dispatchFetch call also now correctly includes
the origin where previously it would just use http://localhost as a
placeholder. This was breaking the proxyToSandbox() call in the worker
itself.


  • Tests
    • Tests included/updated
  • Public documentation
    • Documentation not necessary because: this is an internal implementation of the websocket routing which should be transparent to the end user.

Open with Devin

@aron-cf aron-cf requested a review from a team as a code owner March 6, 2026 17:23
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 6, 2026

🦋 Changeset detected

Latest commit: ab86cd5

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

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 6, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 6, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12794

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12794

miniflare

npm i https://pkg.pr.new/miniflare@12794

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12794

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12794

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12794

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12794

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12794

wrangler

npm i https://pkg.pr.new/wrangler@12794

commit: e144bab

@aron-cf aron-cf force-pushed the vite-plugin-sandboxes branch from 0308fea to 1da9549 Compare March 9, 2026 13:42
devin-ai-integration[bot]

This comment was marked as resolved.

@aron-cf aron-cf force-pushed the vite-plugin-sandboxes branch 2 times, most recently from 0c86c5e to 8df5356 Compare March 9, 2026 17:25
Copy link
Copy Markdown
Contributor

@jamesopstad jamesopstad left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks @aron-cf.

Comment thread packages/vite-plugin-cloudflare/src/__tests__/websockets.spec.ts Outdated
Comment thread packages/vite-plugin-cloudflare/src/__tests__/websockets.spec.ts Outdated
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 10, 2026
@aron-cf aron-cf force-pushed the vite-plugin-sandboxes branch from 6eef425 to 66e0d45 Compare March 10, 2026 11:50
devin-ai-integration[bot]

This comment was marked as resolved.

@aron-cf aron-cf force-pushed the vite-plugin-sandboxes branch from 1a4724f to 51481aa Compare March 10, 2026 17:59
devin-ai-integration[bot]

This comment was marked as resolved.

This commit ensures that all websocket requests (including those that
use the vite-hmr protocol) are routed to the worker. This fixes a minor
issue where the plugin will drop HMR requests from sandbox preview URLs.

The handler now checks to see if the host matches the pattern used by
sandboxes. `<port>-<sandbox_id>-<token>.localhost`.

The URL provided to the `dispatchFetch` call also now correctly includes
the origin where previously it would just use `http://localhost` as a
placeholder. This was breaking the `proxyToSandbox()` call in the worker
itself.
@aron-cf aron-cf force-pushed the vite-plugin-sandboxes branch from 51481aa to db2b6a4 Compare March 12, 2026 11:14
@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Comment thread .changeset/two-ants-yawn.md Outdated
Co-authored-by: Edmund Hung <me@edmund.dev>
@edmundhung edmundhung merged commit b980af6 into cloudflare:main Mar 12, 2026
36 of 37 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 12, 2026
aron-cf added a commit to cloudflare/sandbox-sdk that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants