Skip to content

fix(cms): Fast Preview never edits the production branch - #8389

Merged
aka-sacci-ccr merged 4 commits into
mainfrom
fix/fast-preview-production-read-only
Nov 6, 2026
Merged

aka-sacci-ccr merged 4 commits into
mainfrom
fix/fast-preview-production-read-only

Conversation

@aka-sacci-ccr

@aka-sacci-ccr aka-sacci-ccr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What is this contribution about?

In a Blocks v7 project with Fast Preview on, a draft is a git branch: every autosave is a commit on the session's branch. Nothing stopped that branch from being the repository's default branch, so a session on production saved straight to the live site.

The way in from the UI: deleting the active draft when it is the last one made the version switcher fall back to production (branch-picker.tsx, confirmDelete → pick(baseBranch)). Once there, just opening a page writes the missing schema @defaults, so browsing alone committed to the default branch.

This closes it at three levels:

1. The last draft stays (version switcher)

  • Delete on the only draft is disabled, with "Keep at least one draft". The rule is checked again when the delete is confirmed, since the other draft may have gone while the dialog was open.
  • Deleting the active draft switches to a sibling draft and never falls back to production.
  • The switcher's New draft logic moved into useStartDraft, so the notice below can reuse it.

2. Production is blocked in the site editor

  • A session can still be on production another way (an older chat, a thread opened on main). There, a v7 Fast Preview session shows only a notice, "Production can't be edited here", with New draft, instead of Preview, Content and Blocks, so nothing that reads or saves the decofile mounts.
  • The header keeps the draft switcher and hides Publish.
  • resolveProductionGate (pure, unit-tested) decides this, through useProductionGate.
  • The gate stays open for v8 (whose base branch holds a CDN draft), Local mode, a connected deco serve and coding sessions.
  • The default branch comes from the server (/git/status → base, the same cache entry as the Fast Preview header). It does not come from useBaseBranch, which says "main" whenever the branch has no PR.
  • A listed draft opens without waiting for that answer; if the answer says it is production, the gate blocks it.
  • A failed refetch keeps the known default branch, so the gate doesn't open on a 429.
  • Once decided for a branch, a later "pending" keeps the decision instead of unmounting the editor.

3. The API fails closed

  • PATCH /api/:org/decofile/:vmcp/:branch refuses the default branch with 409 { code: "default_branch_read_only" }, before anything is queued. Body validation runs first, so invalid bodies still answer 400.
  • The cms /git/rebase and /git/discard refuse it too. A rebase with a base other than the default branch could rewrite production onto it.
  • Unchanged: GET, rpc (the editor reads main's schema through /decofile/:vmcp/main/rpc), publish (it already refused the default branch), and Blocks v8, which never sends PATCH.

e2e

  • Specs that moved main through PATCH now commit through the GitHub stub (commitStubFiles), the way another draft's publish or a push lands.
  • v7 sessions that opened on main now open on a seeded draft.
  • New fast-preview-production.spec.ts covers:
    • the 409 on the default branch, with main's head unchanged, while a draft still writes;
    • the switcher keeping the last draft, allowing a delete once a second draft exists, and deleting the active draft moving to the other one;
    • the notice on production → New draft → the editor.

Companion change: #8390 adds a project switch to stop forms from persisting missing defaults when they open.

How did you verify your code works?

  • bun run verify: exit 0, 13218 pass, 0 fail. tsc --noEmit passes for apps/api, apps/web and packages/e2e.
  • Unit tests:
    • v8-gates.test.ts › "v7 writes to the default branch": PATCH on the default branch → 409 with no commitFiles call; the same PATCH on a draft commits; GET and rpc on main still answer 200.
    • git-compat.test.ts: repoGitRebase / repoGitDiscard throw DefaultBranchWriteError on the default branch.
    • production-gate.test.ts (21 cases) and the onProduction case in site-draft-bar-parts.test.ts.
  • e2e against a throwaway Postgres + NATS:
    • fast-preview-production: 9/9 (--repeat-each=3).
    • compact-page-layout, content-loader-editor, content-protocol-github, site-editor-stale-form, site-editor-breadcrumbs, fast-preview-git-sync and decofile-api: 67/67.
  • Manually, on a local stack: deleting the last draft is blocked in the switcher.

Screenshots/Demonstration

How to Test

  1. Open a v7 project with Fast Preview on and a chat with a single draft.
  2. Open the version switcher and the draft's ⋯ menu. Delete is disabled, with "Keep at least one draft".
  3. Click New draft. Now either draft can be deleted, and deleting the active one switches to the other.
  4. Open a chat whose branch is the default branch (for example, an older chat, or COLLECTION_THREADS_CREATE with branch: "main"). The canvas shows "Production can't be edited here" with New draft, and the header has no Publish. New draft opens the editor on a fresh draft.
  5. PATCH /api/<org>/decofile/<vmcp>/main with any valid block returns 409 default_branch_read_only, and no commit lands on the default branch.
  6. A Blocks v8 project on its base branch still edits its draft normally, and Advanced → Local on production still previews the tunnel.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

Out of scope: useBaseBranch still falls back to "main", so on repos whose default branch has another name the switcher's "Production" label doesn't show. The gate and the API don't rely on it.

🤖 Generated with Claude Code

A Blocks v7 Fast Preview draft is a git branch, so a session on the
repository's default branch saved every autosave straight to production.
Deleting the last draft moved the session there ("read-only production" was
only a label), and opening a page there persisted missing defaults, so just
browsing committed to the live site.

- api: PATCH /decofile refuses the default branch (409
  `default_branch_read_only`) before anything is queued; cms /git/rebase and
  /git/discard refuse it too (a rebase onto another base could rewrite it).
  Reads, rpc and v8's CDN draft are unchanged.
- web: on production a v7 Fast Preview session shows only a notice with
  "New draft" instead of Preview/Content; the header keeps the draft
  switcher and drops Publish. The default branch comes from the server
  (`/git/status` base), not the "main" fallback. Local mode stays open.
- web: the switcher's "New draft" is shared with the notice (useStartDraft).
- e2e: specs that moved `main` through PATCH now commit through the GitHub
  stub; v7 sessions open on a draft; new spec for the guard and the notice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the claude PR authored by a coding agent label Nov 6, 2026
decobot and others added 3 commits November 6, 2026 13:45
Simpler than gating the site editor: the only way a Fast Preview session
reached production from the UI was deleting the last draft, which fell back
to the base branch. Now the version switcher keeps the last draft (Delete is
disabled, saying why) and deleting the active draft never falls back to
production. The API still refuses writes to the default branch.

Drops the production gate, the notice, useStartDraft and the header change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
They never write, so the API guard doesn't touch them; the move to a draft
was only needed by the dropped production notice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…raft

Both guards: the version switcher keeps the last draft (deleting it can't
move a session to production), and a v7 Fast Preview session that is on
production anyway (an older chat, one opened there by hand) shows only a
notice with "New draft" instead of the editor; Publish hides there.

The gate, from review:
- a failed /git/status refetch keeps the known default branch (it used to
  open the editor on production);
- a listed draft opens without waiting for /git/status;
- a CMS session waits for its branch instead of mounting the editor first;
- once decided for a branch, a later "pending" keeps the decision rather
  than unmounting the editor;
- the status placeholder only comes from the same project;
- "New draft" creates one draft per click.

Also: confirmDelete re-checks the last-draft rule; stale docs fixed; the
stale-form spec drops its unused branch parameter; the e2e spec covers the
notice and deleting the active draft.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aka-sacci-ccr
aka-sacci-ccr enabled auto-merge (squash) November 6, 2026 17:34
@aka-sacci-ccr
aka-sacci-ccr merged commit ed1b759 into main Nov 6, 2026
24 checks passed
@aka-sacci-ccr
aka-sacci-ccr deleted the fix/fast-preview-production-read-only branch November 6, 2026 17:37
decocms Bot pushed a commit that referenced this pull request Nov 6, 2026
PR: #8389 fix(cms): Fast Preview never edits the production branch
Bump type: patch

- decocms (apps/api/package.json): 4.556.3 -> 4.556.4
- @decocms/e2e (packages/e2e/package.json): 1.131.3 -> 1.131.4

Deploy-Scope: both
tlgimenes added a commit that referenced this pull request Nov 6, 2026
Main's production gate (#8389) asked useMainSchemaV8 whether a session is
a v7 site and waited on an undecided Local tunnel. This branch replaced
that hook with the project's "Blocks v8 site" switch (useBlocksV8Project)
and removed the undecided tunnel state, so the rebase left the gate
importing a module that no longer exists (tsc and knip failed).

The gate now takes blocksV8 (synchronous, so no "loading" or "error"
waits) and no tunnelUndecided; its tests drop the removed states.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes added a commit that referenced this pull request Nov 6, 2026
Main's #8389 made a v7 site's default branch read-only: the editor shows
the production notice there and PATCH /decofile on it answers 409. The
spec, added on this branch, opened its session on main and asserted the
save landed on main, so after the rebase every case waited on a blocks
panel the production notice replaced. It now seeds a `draft` branch at
main's head (as main's own specs do), opens the session there and checks
the save on that branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes added a commit that referenced this pull request Nov 6, 2026
Port the three default-branch tests main added to v8-gates.test.ts (#8389)
onto this branch's decofile route harness: a PATCH on the default branch
answers 409 default_branch_read_only and commits nothing, the same PATCH
on a draft branch answers 200 and commits, and reads of the default branch
(GET, and status in place of main's rpc, which this branch does not have)
are still served.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes added a commit that referenced this pull request Nov 9, 2026
Main's production gate (#8389) asked useMainSchemaV8 whether a session is
a v7 site and waited on an undecided Local tunnel. This branch replaced
that hook with the project's "Blocks v8 site" switch (useBlocksV8Project)
and removed the undecided tunnel state, so the rebase left the gate
importing a module that no longer exists (tsc and knip failed).

The gate now takes blocksV8 (synchronous, so no "loading" or "error"
waits) and no tunnelUndecided; its tests drop the removed states.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes added a commit that referenced this pull request Nov 9, 2026
Main's #8389 made a v7 site's default branch read-only: the editor shows
the production notice there and PATCH /decofile on it answers 409. The
spec, added on this branch, opened its session on main and asserted the
save landed on main, so after the rebase every case waited on a blocks
panel the production notice replaced. It now seeds a `draft` branch at
main's head (as main's own specs do), opens the session there and checks
the save on that branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes added a commit that referenced this pull request Nov 9, 2026
Port the three default-branch tests main added to v8-gates.test.ts (#8389)
onto this branch's decofile route harness: a PATCH on the default branch
answers 409 default_branch_read_only and commits nothing, the same PATCH
on a draft branch answers 200 and commits, and reads of the default branch
(GET, and status in place of main's rpc, which this branch does not have)
are still served.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes added a commit that referenced this pull request Nov 9, 2026
Main's production gate (#8389) asked useMainSchemaV8 whether a session is
a v7 site and waited on an undecided Local tunnel. This branch replaced
that hook with the project's "Blocks v8 site" switch (useBlocksV8Project)
and removed the undecided tunnel state, so the rebase left the gate
importing a module that no longer exists (tsc and knip failed).

The gate now takes blocksV8 (synchronous, so no "loading" or "error"
waits) and no tunnelUndecided; its tests drop the removed states.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes added a commit that referenced this pull request Nov 9, 2026
Main's #8389 made a v7 site's default branch read-only: the editor shows
the production notice there and PATCH /decofile on it answers 409. The
spec, added on this branch, opened its session on main and asserted the
save landed on main, so after the rebase every case waited on a blocks
panel the production notice replaced. It now seeds a `draft` branch at
main's head (as main's own specs do), opens the session there and checks
the save on that branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes added a commit that referenced this pull request Nov 9, 2026
Port the three default-branch tests main added to v8-gates.test.ts (#8389)
onto this branch's decofile route harness: a PATCH on the default branch
answers 409 default_branch_read_only and commits nothing, the same PATCH
on a draft branch answers 200 and commits, and reads of the default branch
(GET, and status in place of main's rpc, which this branch does not have)
are still served.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude PR authored by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant