Repository navigation
fix(blocks): match draft override blocks by percent-decoded key - #450
Merged
Merged
Conversation
The pull-based `?__draft=` preview merges the Studio sandbox decofile on top of the site's published blocks in `loadBlocks()`. The two decofiles disagree on how block keys spell special characters: the published decofile percent-encodes them (`pages-Home%20(principal)-…`) while the Studio draft sandbox emits them raw (`pages-Home (principal)-…`). The old key-merge is literal, so a raw-keyed draft block was ADDED alongside the encoded published block instead of REPLACING it — leaving two `pages-` blocks with the same `.path`. `findPageByPath` returns the first (published) one, so the draft edit silently never rendered: the preview badge showed, headers/cookie/cache-bypass were all correct, but the page content stayed published. Measured against casaevideo's live decofiles this hit 78 of 107 pages (~73%) — every page whose block name contains a space or accent, home and afiliados included. Pages with plain ASCII keys (disney, login, natal, ofertas) were unaffected, which is why it looked intermittent. Fix: canonicalise base keys by `decodeURIComponent` when applying an override so an override block finds and displaces its differently-encoded twin (and a `null` override removes it). Exact-match keys — the admin `withBlocksOverride` partial-render path — are unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
🎉 This PR is included in version 7.34.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Problem
The pull-based
?__draft=preview (TanStack #442, Next #409) merges the Studio sandbox decofile on top of the site's published blocks inloadBlocks(). But the two decofiles disagree on how block keys spell special characters:/(home) block key/.decofile, the base)pages-Home%20(principal)-287364(percent-encoded)_sandbox/decofile, the override)pages-Home (principal)-287364(raw)The merge was a literal key-merge:
So the raw-keyed draft block was added alongside the encoded published block, leaving two
pages-blocks with the same.path.findPageByPathreturns the first match ingetAllPages()order — the published block was already inblockData, the draft was appended after, so ties resolve to published. The draft edit silently never rendered: preview badge showed,no-store/noindex/cookie/edge-cache-bypass were all correct, but the page content stayed published.Impact
Measured against casaevideo's live published vs sandbox decofiles: 78 of 107 pages (~73%) were affected — every page whose block name contains a space or accent (
Home (principal),Afiliados - Performance, …). The 29 pages with plain ASCII keys (disney,login,natal,ofertas) worked, which is exactly why it looked intermittent. All 70 special-char blocks in the sandbox URL-decode to the published key 1:1 — a systematic encoding contract mismatch, not a fluke.Fix
Canonicalise base keys with
decodeURIComponentwhen applying an override, so an override block finds and displaces its differently-encoded twin (anulloverride removes it too). Defensive: a malformed%sequence falls back to the raw key rather than throwing. Exact-match keys — including the adminwithBlocksOverridepartial-render path — are byte-for-byte unchanged.Tests
3 new regression tests in
loader.test.ts(home encoded-vs-raw twin collapses to one block rendering the draft; plain keys still replace;nulldraft removes the encoded twin). Full@decocms/blockssuite green: 1396/1396, typecheck clean.Follow-up (not here, cross-repo)
The root contract mismatch is that preview-studio emits raw block keys while the published decofile encodes them. Aligning the source is worth doing separately; this framework-side canonicalisation is the defensive fix at the deterministic merge chokepoint (and an override should always replace, never duplicate).
🤖 Generated with Claude Code
Summary by cubic
Fixes draft preview merging by matching override blocks to base blocks using percent-decoded keys, so raw Studio keys replace their encoded published twins. Restores draft rendering for pages with spaces/accents without changing exact-match override behavior.
?__draft=overrides; fall back to raw key on decode errors.pages-entries.Written for commit e2f66ec. Summary will update on new commits.