Repository navigation
feat(deploy): honor Worker-entry cache setters for ISR deploys - #1821
Conversation
Older apps that wired a cache backend imperatively in their Worker entry (setCacheHandler / setDataCacheHandler / setCdnCacheAdapter) were blocked on deploy because the ISR cache-adapter check only inspected the Vite config. Add workerEntryHasCacheHandler() so those backwards-compatible entries are still considered configured. Also drop the cdn adapter suggestion from formatMissingCacheAdapterError; the message now points only to the kvDataAdapter() data cache.
|
/bigbonk review |
commit: |
|
There was a problem hiding this comment.
Review: feat(deploy): honor Worker-entry cache setters for ISR deploys
Verified the change builds, lints, type-checks, and the new tests pass (vp check + targeted tests/deploy.test.ts runs green).
Summary
This is a clean, well-scoped backwards-compat fix. The ISR deploy gate now passes when either the Vite config or the Worker entry configures a cache backend, which correctly unblocks older apps that wired setCacheHandler / setDataCacheHandler / setCdnCacheAdapter imperatively in worker/index.{ts,js}. This is logically consistent with #1800 (which deprecated those setters but kept them functional).
What's good
- Candidate paths match repo conventions.
worker/index.ts/worker/index.jsmirrorshasWorkerEntry(deploy.ts:196-198) and the auto-generated entry path. Worker entries are never.mjsanywhere in the codebase, so omitting.mjs(unlikeviteConfigHasCacheAdapter, which checks it for vite configs) is correct. - Leniency model is intentional and documented. Unreadable entry →
true(don't block); missing entry →false(defer to other checks). Because the gate ANDs both checks (!viteConfigHasCacheAdapter(root) && !workerEntryHasCacheHandler(root)), the missing/false asymmetry vsviteConfigHasCacheAdapteris sound —viteConfigHasCacheAdapteralready returnstruefor a missing config, so a missing worker entry returningfalsedoesn't accidentally block anything. - No dev/prod parity concern. This cache-adapter gate exists only in
deploy.ts; there's no duplicate logic in the prod/dev/CLI servers that needs the same fix. - Tests are thorough and isolated. All three setters, both
.ts/.js, no-setter, and missing-entry cases are covered.tmpDiris recreated per test viabeforeEach, so the "no Worker entry" case is genuinely clean.
Minor notes (non-blocking)
-
Regex matches commented-out / string-literal calls.
\b(?:setCacheHandler|...)\s*\(is a plain text scan, so a commented-out// setCacheHandler(...)would count as "configured" and let a deploy through. Given the explicitly-documented favor-false-positive-over-false-negative model (matchingviteConfigHasCacheAdapter), this is an acceptable tradeoff — just flagging it as a known heuristic limitation. -
CDN removal from the error message.
cdnAdapter()/cache.cdnis still a fully-supported, documented option (index.ts:728-733,shims/cdn-cache.ts). Dropping it fromformatMissingCacheAdapterErroris a reasonable UX simplification (point users at the KV data cache that the auto-scaffoldedVINEXT_KV_CACHEbinding backs), but confirm this is a deliberate "data-cache-first" messaging choice rather than an implication thatcdnis going away. The test now asserts the message no longer references the CDN adapter, which locks in that intent.
Verdict
Approve. Correct, minimal, well-tested backwards-compat fix that matches the deprecation direction of #1800. The two notes above are informational only.
|
Review posted to PR #1821. SummaryThis PR is a clean, well-scoped backwards-compat fix. I verified it builds, lints, type-checks, and the new tests pass. Verdict: Approve. Key findings:
Two non-blocking notes raised:
|
What
When deploying an ISR/cached app, the deploy command requires a cache adapter to be configured. Previously this check only inspected the Vite config (
vinext({ cache })), so apps that wired a cache backend imperatively in their Worker entry were incorrectly blocked.This PR:
Adds backwards-compat detection for Worker-entry cache setters. New exported
workerEntryHasCacheHandler(root)scans an existing user-authored Worker entry (worker/index.ts/worker/index.js) forsetCacheHandler/setDataCacheHandler/setCdnCacheAdaptercalls. The ISR deploy gate now passes when either the Vite config or the Worker entry configures a backend. It mirrorsviteConfigHasCacheAdapter's leniency (unreadable entry treated as configured; missing entry returnsfalse).Removes the CDN part from
formatMissingCacheAdapterError. The error message no longer suggests thecdnAdapter()import/option and points only at thekvDataAdapter()data cache.Testing
workerEntryHasCacheHandlertest block covering all three setters, both.ts/.jsentries, the no-setter case, and the missing-entry case.vp checkand the targetedtests/deploy.test.tscases pass.