Skip to content

fix(cloudflare): respect explicit cache.enabled: false in wrangler config#17376

Open
astrobot-houston wants to merge 1 commit into
mainfrom
triagebot/fix-17375
Open

fix(cloudflare): respect explicit cache.enabled: false in wrangler config#17376
astrobot-houston wants to merge 1 commit into
mainfrom
triagebot/fix-17375

Conversation

@astrobot-houston

Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where cloudflareConfigCustomizer would silently override an explicit cache: { enabled: false } in the user's wrangler config when cacheCloudflare() was configured as a cache provider.

Root Cause

In packages/integrations/cloudflare/src/wrangler.ts, the cache auto-enable condition used a falsy check:

// Before
cache: needsWorkerCache && !config.cache?.enabled ? { enabled: true } : undefined,

!config.cache?.enabled evaluates to true for both:

  • config.cache is undefined — cache not configured at all (correct: should auto-enable)
  • config.cache.enabled is false — user explicitly opted out (incorrect: should be respected)

Fix

Changed to a strict === undefined check so auto-enabling only applies when the user hasn't set the cache field at all:

// After
cache: needsWorkerCache && config.cache?.enabled === undefined ? { enabled: true } : undefined,

An explicit cache: { enabled: false } is now preserved through the build. This is consistent with how other fields in the same function (main, compatibility_date, assets) handle their defaults using nullish coalescing.

Why this matters

Workers Cache supports per-entrypoint enablement via the exports block. A valid pattern is to leave the top-level enabled: false while enabling cache on specific named entrypoints — e.g., an uncached gateway entry that routes into a cached worker export. Previously the only workaround was post-processing dist/server/wrangler.json after the build.

Testing

Four new unit tests added under a worker cache describe block in packages/integrations/cloudflare/test/wrangler.test.ts:

  1. Auto-enables cache when needsWorkerCache: true and cache is unconfigured
  2. Does not enable cache when needsWorkerCache: false
  3. Does not override when cache is already enabled: true
  4. Does not override explicit cache.enabled: false (regression test for this issue)

Confirmed working by issue reporter @skezo against the preview build.

Closes #17375

…config (#17375)

Change the cache auto-enable check from a falsy check (`!config.cache?.enabled`)
to a strict undefined check (`config.cache?.enabled === undefined`) so that an
explicit `cache: { enabled: false }` in the user's wrangler config is not
overridden to `{ enabled: true }`.
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 474b589

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified Reporter confirmed the triage bot fix works pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@astrojs/cloudflare: cacheCloudflare() overrides an explicit cache.enabled: false in wrangler config

1 participant