Repository navigation
fix: share one Cloudflare platform proxy between Vite servers - #17368
Merged
teemingc merged 3 commits intoOct 14, 2026
Merged
Conversation
Track how many servers set up the proxy and dispose it only when the last one closes, so a short-lived second server no longer disposes the proxy the dev server is using, and concurrent servers start a single proxy instead of one each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/ad1c49baba331c5a1fdbb77643975736cb05e45aOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: ad1c49b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
|
Looks good once the tests pass and merge conflicts are resolved. |
Preserve the Deno caches descriptor fix when sharing the Cloudflare platform proxy. Gate the concurrent rejection test on both servers awaiting the proxy and cover immediate rejection separately. Co-authored-by: Copilot App <[email protected]>
Merged
teemingc
added a commit
that referenced
this pull request
Oct 14, 2026
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @sveltejs/[email protected] ### Minor Changes - feat: support `report-sha256`/`report-sha384`/`report-sha512` CSP hash-reporting keywords ([#17398](#17398)) - feat: emit a `sveltekit.endpoint` span for `+server` handlers when server tracing is enabled ([#17325](#17325)) ### Patch Changes - fix: don't treat every module as server-only when the project is inside a `server` directory ([#17376](#17376)) - fix: continue deployment recovery when service worker updates fail ([#17440](#17440)) - fix: infer prerendered MIME types from generated files ([#17381](#17381)) - fix: leave generated files alone when their contents are unchanged ([#17310](#17310)) - fix: leave focus in the parent page when an app in an unfocused iframe starts or navigates ([#17297](#17297)) - fix: don't warn about Storybook's Vite plugins that use `transformIndexHtml` ([#17373](#17373)) ## @sveltejs/[email protected] ### Patch Changes - fix: start the dev server on runtimes such as Deno that define `caches` as a getter-only global ([#17401](#17401)) - fix: start one platform proxy for concurrent Vite servers and keep it alive until the last one closes ([#17368](#17368)) - fix: support `Span#setStatus` and `Span#updateName` on local emulation of Cloudflare `tracing` ([#17400](#17400)) - Updated dependencies: - @sveltejs/[email protected] ## @sveltejs/[email protected] ### Patch Changes - fix: keep the detected Bun minor in the resolved runtime ([#17331](#17331)) - Updated dependencies: - @sveltejs/[email protected] ## @sveltejs/[email protected] ### Patch Changes - fix: emit component types for the installed Svelte version, rather than the oldest one the `svelte` dependency range allows ([#17330](#17330)) --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tee Ming <[email protected]>
longrunningprocess
added a commit
to CanIL-CA/tabitha
that referenced
this pull request
Oct 14, 2026
…uard (#198) 8.0.1 starts one shared platform proxy for concurrent Vite servers (sveltejs/kit#17368), which fixes the SQLITE_BUSY_RECOVERY race (kit#17344) the guard worked around. Measured without the guard: all unit tests pass and run time is unchanged. Co-authored-by: Claude Sonnet 5.5 <[email protected]>
teemingc
added a commit
that referenced
this pull request
Oct 16, 2026
…7432) ## Summary Closes #17429. The Cloudflare adapter's Vite plugin currently reads the wrangler config once at `configureServer` time and never re-reads it. Edit `wrangler.toml`/`wrangler.jsonc` and the platform proxy keeps serving the stale config until the user manually restarts the dev server. This PR watches the resolved wrangler config path on the Vite dev server's watcher. When the file is edited, we call `server.restart()`. The existing teardown (`closeServer` → `dispose`) tears the shared platform proxy down, and `configureServer` → `setup` creates a fresh one — `getPlatformProxy(options)` re-reads the config file on each call, so the restart alone is enough to pick up the new config. ## What changed - **`packages/adapter-cloudflare/index.js`** — `setup` now accepts the Vite dev/preview server and, when it's a dev server with a `watcher`, resolves the wrangler config path via `unstable_readConfig({ config: options.configPath })` and installs a `change` listener that calls `server.restart()` when the resolved config file is touched. Preview servers have no `watcher`, so they skip the hookup. Resolution via `unstable_readConfig` means we honour the same resolution rules wrangler itself uses (`wrangler.toml`, `wrangler.jsonc`, `--config`, etc.). - **`packages/adapter-cloudflare/index.spec.js`** — two new tests: - `restarts the dev server when the wrangler config file changes` — mocks `unstable_readConfig` to return a resolved path, asserts `server.restart()` is called on the matching change and not on any other file. - `does not install a config watcher when wrangler cannot resolve a config path` — proves we're defensive about the `{ configPath: undefined }` case. ## Local verification ``` $ ./node_modules/.bin/vitest run index.spec.js Test Files 1 passed (1) Tests 8 passed (8) ``` 6 existing tests + 2 new, all green. Install was `pnpm install --filter @sveltejs/adapter-cloudflare` on Node 24 / pnpm 12. ## Notes - Builds directly on top of #17368 (@glw907, merged 2026-10-14) — the shared-proxy teardown that this restart relies on landed one minute before the author filed this issue. The two together give `wrangler config change → one proxy restart across both dev servers`. - The listener is attached per-server. If the SSR dev server triggers the restart, Vite tears both down (SvelteKit SSR + client share the proxy via `__sveltekit_cloudflare_platform_setup`), and the next `setup` runs with the fresh config. - The restart does not debounce — if an editor saves twice in a row, Vite's own `server.restart()` already queues them. ## Changeset Added patch changeset for `@sveltejs/adapter-cloudflare`. cc @teemingc — thanks for the sharp report with the Wrangler file:line references. If you'd rather drive this yourself I'm happy to close and move my test coverage into your PR. 🤖 Used Claude Code for the research pass and to cross-check the mock shapes against existing adapter-cloudflare tests; every assertion signed off by me. --------- Co-authored-by: Tee Ming <[email protected]>
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #17344
virtual_workers_module()keeps one platform proxy onglobalThis.__sveltekit_cloudflare_platform, but nothing records which servers use it. That breaks two ways when more than one Vite server runs in the same process:if (globalThis.__sveltekit_cloudflare_platform) return;guard before either assigns the global, so each callsgetPlatformProxy()and two workerd instances open the same.wrangler/state. Vitest projects that extend a config using the adapter hit this. Starting one proxy also stops the leaked second proxy from keeping Vitest alive after the run.closeServerdisposes the proxy and clears the global, including a server whose setup returned early and never created it. When a plugin starts a short-lived second server undervite dev(for examplecreateServer()thenserver.close()inbuildStart), closing it disposes the dev server's proxy. Every request that readscloudflare:workersthen fails withCannot access cloudflare:workers in a prerenderable route.This stores the pending
getPlatformProxy()promise and a server count on a second global,__sveltekit_cloudflare_platform_setup. Each setup increments the count and awaits the shared promise; each close decrements it, and the close that reaches zero disposes the proxy. A restarting server is set up before the old one closes, socloseServerno longer checksreason. IfgetPlatformProxy()rejects, the shared state is cleared so the next server can retry.As with the old early return, the first server's adapter options configure the shared proxy. One edge case remains: if a later plugin's
configureServerthrows while a server is being created, that server has already incremented the count but is never closed, so the count does not return to zero.#16705 and #16811 touch the same function and will need a rebase.
Adds tests to
index.spec.jsfor a second server closing while the first stays open, two servers created concurrently, and a failed start followed by a retry. The first two fail without this change. The existing restart test still passes.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkpnpm lint,pnpm checkand the adapter's unit tests pass. The adapter's e2e suite could not run locally because Playwright'schromechannel is not installed.Changesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits