fix(cloudflare): respect explicit cache.enabled: false in wrangler config#17376
Open
astrobot-houston wants to merge 1 commit into
Open
fix(cloudflare): respect explicit cache.enabled: false in wrangler config#17376astrobot-houston wants to merge 1 commit into
cache.enabled: false in wrangler config#17376astrobot-houston wants to merge 1 commit into
Conversation
…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 }`.
1 task
|
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.
Summary
Fixes a bug where
cloudflareConfigCustomizerwould silently override an explicitcache: { enabled: false }in the user's wrangler config whencacheCloudflare()was configured as a cache provider.Root Cause
In
packages/integrations/cloudflare/src/wrangler.ts, the cache auto-enable condition used a falsy check:!config.cache?.enabledevaluates totruefor both:config.cacheisundefined— cache not configured at all (correct: should auto-enable)config.cache.enabledisfalse— user explicitly opted out (incorrect: should be respected)Fix
Changed to a strict
=== undefinedcheck so auto-enabling only applies when the user hasn't set thecachefield at all: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
exportsblock. A valid pattern is to leave the top-levelenabled: falsewhile 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-processingdist/server/wrangler.jsonafter the build.Testing
Four new unit tests added under a
worker cachedescribe block inpackages/integrations/cloudflare/test/wrangler.test.ts:needsWorkerCache: trueand cache is unconfiguredneedsWorkerCache: falseenabled: truecache.enabled: false(regression test for this issue)Confirmed working by issue reporter @skezo against the preview build.
Closes #17375