Skip to content

breaking: Move cloudflare bindings from platform to cloudflare:workers - #16754

Open
ottomated wants to merge 19 commits into
adapter-getRequest-setResponsefrom
remove-cloudflare-platform
Open

breaking: Move cloudflare bindings from platform to cloudflare:workers#16754
ottomated wants to merge 19 commits into
adapter-getRequest-setResponsefrom
remove-cloudflare-platform

Conversation

@ottomated

Copy link
Copy Markdown
Contributor

Breaking #16705 into smaller pieces; this is the first step of making the dev environment closer to the workerd runtime. Instead of accessing Cloudflare bindings on platform.env, you would do the following:

import { env } from 'cloudflare:workers';

export function GET({ request }) {
  const value = await env.KV.get('key'); // instead of platform.env
  const userCountry = request.cf.country; // instead of platform.cf
  const cache = caches.open('name'); // instead of platform.caches
}

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 12, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 0f6072c:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/0f6072c6b23b162fd2e8bf94290bea14a8104194

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

@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0f6072c

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 Major

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

@ottomated ottomated changed the title Remove cloudflare platform breaking: Move cloudflare bindings from platform to cloudflare:workers Aug 12, 2026
Comment thread packages/adapter-cloudflare/test/apps/workers/src/routes/prerender/+server.js Dismissed
@svelte-docs-bot

Copy link
Copy Markdown

Comment thread packages/adapter-cloudflare/package.json Outdated
Comment thread packages/adapter-cloudflare/src/virtual-cloudflare-workers.js Outdated
Comment thread documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md
Comment thread documentation/docs/60-appendix/35-migrating-to-sveltekit-3.md Outdated
@ottomated
ottomated force-pushed the remove-cloudflare-platform branch from b3c32be to 11e9241 Compare August 13, 2026 21:30
Comment thread documentation/docs/60-appendix/35-migrating-to-sveltekit-3.md Outdated
Comment thread documentation/docs/60-appendix/35-migrating-to-sveltekit-3.md Outdated
@ottomated
ottomated force-pushed the remove-cloudflare-platform branch from f44c3dc to 9d6c489 Compare August 13, 2026 21:47
Comment thread documentation/docs/60-appendix/35-migrating-to-sveltekit-3.md
Comment thread packages/adapter-cloudflare/src/virtual-cloudflare-workers.js Outdated
Comment on lines +143 to +148
enterSpan() {
throw new Error('tracing is not available in dev mode');
},
startActiveSpan() {
throw new Error('tracing is not available in dev mode');
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should these just be no-ops in dev?

@teemingc teemingc Aug 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if it would be confusing if these didn't work and the user didn't know. SvelteKit tracing does work during dev (but I'm not sure what these functions do).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They are now no-ops, I don't think it'll be too confusing (and there's nothing we can do until they give us a non-mock implementation)

Comment thread packages/adapter-cloudflare/src/virtual-cloudflare-workers.js
prerendering = true;
}

const als = new AsyncLocalStorage();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need ALS here? isn't env always going to be the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They export a withEnv function like below. We could stub that but it's easy enough to get working

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is withEnv for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mocking the env object for child functions that import it globally (https://developers.cloudflare.com/workers/runtime-apis/bindings/#overriding-env-values)

Comment thread documentation/docs/60-appendix/35-migrating-to-sveltekit-3.md
Comment thread packages/adapter-cloudflare/test/apps/workers/package.json Outdated
Comment thread documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md Outdated
@ottomated
ottomated force-pushed the remove-cloudflare-platform branch from 0374920 to 2ce7ca5 Compare August 14, 2026 20:46
elliott-with-the-longest-name-on-github pushed a commit that referenced this pull request Aug 14, 2026
as suggested in #16754, modernizes the cloudflare adapter's docs to
mention `wrangler types`. No changeset because docs-only

---

### Please don't delete this checklist! Before submitting the PR, please
make sure you do the following:

- [x] It's really useful if your PR references an issue where it is
discussed ahead of time. In many cases, features are absent for a
reason. For large changes, please create an RFC:
https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it
solves.
- [ ] Ideally, include a test that fails without this PR but passes with
it.

### Tests

- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint` and `pnpm check`

### Changesets

- [x] If your PR makes a change that should be noted in one or more
packages' changelogs, generate a changeset by running `pnpm changeset`
and following the prompts. Changesets that add features should be
`minor` and those that fix bugs should be `patch`. Please prefix
changeset messages with `feat:`, `fix:`, or `chore:`.
@ottomated
ottomated force-pushed the remove-cloudflare-platform branch from 3fb8a2f to 0494d35 Compare August 14, 2026 23:32
@ottomated
ottomated force-pushed the remove-cloudflare-platform branch from 5bb5fd7 to 0a289ea Compare August 15, 2026 05:57
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.

4 participants