Skip to content

fix(cloudflare): avoid duplicating user KV namespaces when injecting SESSION#16652

Merged
matthewp merged 1 commit into
withastro:mainfrom
greatjourney589:fix/cloudflare-session-kv-duplication-16590
May 7, 2026
Merged

fix(cloudflare): avoid duplicating user KV namespaces when injecting SESSION#16652
matthewp merged 1 commit into
withastro:mainfrom
greatjourney589:fix/cloudflare-session-kv-duplication-16590

Conversation

@greatjourney589
Copy link
Copy Markdown
Contributor

Closes #16590

Changes

  • Fixes a regression introduced in fix(cloudflare): preserve existing KV namespace bindings when injecting SESSION #16555 where user-declared KV namespace bindings (e.g. RATE_LIMIT, CACHE) appear twice in the generated dist/server/wrangler.json, causing wrangler to fail with "<binding> assigned to multiple KV Namespace bindings.".
  • The Astro Cloudflare config customizer now returns only the auto-injected SESSION binding from kv_namespaces, instead of pre-merging the user's existing bindings into the output.
  • @cloudflare/vite-plugin already merges the customizer's output with the user's wrangler config, so echoing the user's bindings caused the duplication.
  • Removed the now-unused withSessionKVBinding() helper.
  • Added a changeset (@astrojs/cloudflare patch).

Affected versions reported in the issue: @astrojs/cloudflare@13.3.0–13.3.1 + astro@6.2.x. Last working combination was astro@6.1.9 + @astrojs/cloudflare@13.2.1, which matches the pre-#16555 behavior this PR restores.

Testing

  • Updated two existing assertions in packages/integrations/cloudflare/test/wrangler.test.ts that locked in the buggy merged-output shape.
  • Added a dedicated regression test does not include user-declared KV bindings in the output (regression #16590) covering the multi-binding scenario from the issue (RATE_LIMIT + CACHE declared by the user) and asserting the customizer returns only [{ binding: 'SESSION' }].
  • All 25 tests in wrangler.test.ts pass locally.

Docs

No documentation changes needed. The fix restores documented and previously-shipped behavior — the public API and configuration surface (sessionKVBindingName, automatic SESSION binding provisioning) are unchanged.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 7, 2026

🦋 Changeset detected

Latest commit: ba3e0ac

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

@greatjourney589 greatjourney589 changed the title fix(cloudflare): avoid duplicating user KV namespaces when injecting … fix(cloudflare): avoid duplicating user KV namespaces when injecting SESSION May 7, 2026
@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label May 7, 2026
@matthewp matthewp merged commit 98c32cc into withastro:main May 7, 2026
22 checks passed
@astrobot-houston astrobot-houston mentioned this pull request May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[@astrojs/cloudflare] User-declared KV namespaces are duplicated in generated dist/server/wrangler.json (13.3.x + astro 6.2.x)

2 participants