Skip to content

fix: dispose Cloudflare platform proxy when Vite servers close - #16976

Closed
svelte-triage-bot[bot] wants to merge 2 commits into
version-3from
triage/kit-16919-dispose-cloudflare-proxy
Closed

svelte-triage-bot[bot] wants to merge 2 commits into
version-3from
triage/kit-16919-dispose-cloudflare-proxy

Conversation

@svelte-triage-bot

Copy link
Copy Markdown
Contributor

Closes #16919

The Cloudflare adapter no longer creates its platform proxy during builds, but the proxy created for Vite dev and preview servers was still retained after those servers closed.

This change retains the proxy in the adapter plugin and disposes it:

  • through Vite's awaited closeBundle lifecycle for dev servers
  • through the preview server's close() lifecycle
  • idempotently when multiple close hooks run
  • while clearing the global proxy so a later server can create a fresh instance

Added focused tests covering dev and preview teardown and a patch changeset.

Verification:

  • pnpm -F @sveltejs/adapter-cloudflare test:unit
  • pnpm -F @sveltejs/adapter-cloudflare check
  • pnpm -F @sveltejs/kit test:unit
  • pnpm check
  • pnpm lint
  • Cloudflare workers fixture build, with zero workerd processes before and after

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 2ad1f7e:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/2ad1f7ed00e4a6b017749952a5c06a20f7ba10cd

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16976

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2ad1f7e

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-cloudflare Patch

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

@teemingc
teemingc marked this pull request as ready for review September 23, 2026 17:35
teemingc
teemingc previously approved these changes Sep 23, 2026
@teemingc
teemingc dismissed their stale review September 23, 2026 17:38

checking if #16754 already fixed this


describe('virtual workers module', () => {
test('disposes the platform proxy when the dev server closes', async () => {
const plugin = adapter().vite?.plugins?.pre?.[0];

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.

Cloudflare adapter unit tests read the vite plugin via plugins?.pre?.[0], but the adapter now returns plugins as a plain array, so the plugin resolves to undefined and the tests throw a TypeError.

Fix on Vercel

@teemingc

Copy link
Copy Markdown
Member

already fixed by #16754

@teemingc teemingc closed this Sep 23, 2026
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.

emulate() never disposes the platform proxy, so every build leaks a workerd

1 participant