Repository navigation
feat(cli): KV sync for Fresh + deco sites (one-pass block keys, keep emptied redirect blocks) [7.x] - #830
feat(cli): KV sync for Fresh + deco sites (one-pass block keys, keep emptied redirect blocks) [7.x]#830hugo-ccabral wants to merge 3 commits into
Conversation
…emptied redirect blocks) `deco-sync-blocks-to-kv` / `deco-migrate-blocks-to-kv` now detect a Fresh + deco repo (deno.json(c), no package.json — the cfworkers-builder's rule) and write a decofile Fresh's runtime can read: - block keys are decoded once, like deco's `parseBlockId`; decoding further turns `a%2520b.json` into `a b` where Fresh expects `a%20b`; - a redirect block whose rules all moved to `redirect:<id>:<path>` keys is kept with `redirects: []` instead of dropped, because Fresh resolves blocks by name and a routes config may reference it; - no synthetic `__csv_redirects__*` blocks (Fresh loads CSVs at runtime); - no `/_cache/purge` call (Fresh has no such endpoint). TanStack repos produce the same output as before. Both scripts now share `readKvDecofile`, so a seed and a sync can't disagree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Verdict: BLOCK — the Fresh branch passes through Blocking
Worth fixing
Checked, fine
|
…intact Review of #830: - a kept singular `website/loaders/redirect.ts` block was rewritten by the split to `redirects: [entry]`; Fresh's loader reads `props.redirect`, so a glob, query or long-path rule silently stopped redirecting. Fresh now gets the original block back. - Fresh treats a `/:param` source as a URLPattern. It was moved to KV as a literal path and never matched. `splitExactRedirects` takes an optional `keepInDecofile`, and the Fresh sync keeps `/:` sources in the decofile. TanStack calls it without the option: same output as before. - `Object.hasOwn` instead of `in` for the kept-block check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Triage of the review, fixed in 502601e:
Tests: |
Found by an end-to-end run on a real Fresh site: Fresh applies a redirect block only when the routes config references it, except `website/loaders/redirect.ts` blocks, which the `website/loaders/redirects.ts` collector gathers by type. A KV key applies to every request, so moving a `std/x/redirects` block made an orphan rule (never applied on Fresh today) start redirecting. On a Fresh repo, only exact sources of `website/loaders/redirect.ts` blocks move, and only when the collector is in the decofile. Everything else stays exactly as Fresh resolves it, verbatim. Also kept: `/:param` (URLPatterns in Fresh) and absolute URLs (Fresh keys those by the full URL, so they never match). `keepInDecofile` now gets the source as written. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The Fresh KV reader is deco-cx/deco#1280, and the router side is deco-cx/apps#1709. The control-plane side is decocms/control-plane#377. Rollout order: this PR is released first, because the syncer and builder call |
Why
Fast deploy is coming to Fresh + deco sites running on Cloudflare Workers (deco-cx/deco
@deco/deco/workerd). They will read their decofile from the same KV contract the TanStack sites use, written by this CLI, which the cfworkers-builder and the operator'sdecofile-synceralready run for every site. Context: decocms/control-plane#373.Two things in today's output break a Fresh reader:
%is left. Fresh'sparseBlockIddecodes once, and blocks reference each other by that key.Home%2520Page.jsonbecomesHome Pagehere andHome%20Pageon Fresh.redirect:<id>:<path>keys, the block is deleted. Fresh resolves blocks by name, so a routes config that references astd/x/redirectsblock would fail to resolve.What
readKvDecofile(inlib/kv-snapshot.ts) is now the one place bothdeco-sync-blocks-to-kvanddeco-migrate-blocks-to-kvbuild the decofile and its exact redirects. On a Fresh repo (deno.json(c)and nopackage.json, the same rule as the cfworkers-builder'sisDenoSite), it:singleDecodeBlockName, which already existed for this reason);{ ...block, redirects: [] };__csv_redirects__*blocks, because Fresh loads CSVs at runtime (redirectsFromCsv);syncskips the/_cache/purgecall, an endpoint only the TanStack worker has.Exact redirects still move to per-key KV entries on Fresh, as on TanStack. Detecting the framework from the repo means the builder and the syncer call the CLI unchanged.
TanStack repos: same output as before.
Tests
scripts/lib/kv-snapshot.test.ts: a Fresh repo gets one-pass keys, the emptied block kept, the glob left in the decofile, and the exact rule inexact. A TanStack repo gets the old output. Also coversisFreshRepo.vitest run packages/blocks-cli/scripts/lib/: 61 passed.tsc --noEmiton blocks-cli: no errors in the changed files. 6 errors exist inscripts/migrate/*.test.ts(TailwindConfigExtract/MigrationContextfixtures), which this PR doesn't touch.🤖 Generated with Claude Code
Summary by cubic
Makes
deco-sync-blocks-to-kvanddeco-migrate-blocks-to-kvwrite a decofile a Fresh + deco site can read, so fast deploy works for those sites without changing how the builder or syncer call the CLI. TanStack repos get the same output as before.deno.json(c), nopackage.json), block keys are decoded once to match Fresh'sparseBlockId, and no synthetic CSV redirect blocks are written.website/loaders/redirect.tsblocks move to KV, and only when thewebsite/loaders/redirects.tscollector is in the decofile; other Fresh redirect blocks stay verbatim, since a KV key applies to every request and would trigger rules Fresh never applied.props.redirectshapes,/:paramsources, and absolute URLs keep working./_cache/purgecall for Fresh sites, since only the TanStack worker exposes that endpoint.readKvDecofile, so a one-shot seed and a CI sync can't produce different snapshots.Written for commit 7a48102. Summary will update on new commits.