Skip to content

feat(ui-react): rebuild the admin edit route on DocForm and core's editor store (closes S1) (5b(ii)) - #42

Merged
jherr merged 1 commit into
mainfrom
cursor/admin-edit-route-d21e
Nov 6, 2026
Merged

jherr merged 1 commit into
mainfrom
cursor/admin-edit-route-d21e

Conversation

@jherr

@jherr jherr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements the second half of cms-refactor-plan.md § Phase 5, 5b: "the admin edit route rebuilt on it (closes the S1 leak)". It also wires 5a's save/act into the editor.

Merge chain: step 22 of 24. Base: main. Merge it right after #43. The branch is main 3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit 2767e37 (tree aa470aa).

Before the merge chain, this PR's diff against 5a also showed R1a's squash and the whole A stack. This was the first branch to hold both the A stack (1e/1d/R2/5b(i)) and the B/C stack (2b/2c/3a/4a–4d/5a). Every conflict is recorded below so the merges can be replayed.

What

The admin edit route (edit.$collection.$id.tsx) is now composition and no longer renders fields itself.

  • DocForm, via useDocForm, owns field state: read and write access, showWhen, field errors, the proposal highlight and relation titles.
    • The aside's controls (published, publishAt, unpublishAt, locale) write through form.setValue.
    • The header buttons and Ctrl/⌘+S call form.submit({ publish, overwrite }), so every save goes through TanStack Form's handleSubmit.
  • Core's createDocEditorStore owns everything else: the baseline, optimistic concurrency, conflict reload and overwrite, busy/status, and 5a's state and availableActions.
  • Saving. onSubmit(patch) calls ed.save, which calls 5a's save({ collection, id, doc: patch, expectedRevision, expectedPendingVersion, publish }).
    • While nothing is stored yet, the whole document is sent, so a translation's prefilled fields survive.
    • The result's doc becomes the baseline.
  • Workflow actions.
    • Decision buttons: the strategy's availableActions that carry no document (approve, reject, discard, publish an approved change, custom steps) are buttons with the strategy's label and tone. They run ed.act, which calls 5a's act.
    • Discard draft is now the strategy's discard action.
    • Reviewers can approve from inside the document.
  • Save buttons follow availableActions:
    • edit → Save, or Publish changes when draft is offered too.
    • submit → Submit for review.
    • draft, for publishers, adds Save draft.
  • Badge: state.label appears next to the revision.
  • Kept:
    • delete with the references warning;
    • share preview;
    • the editing agent's propose and Diff approve;
    • assignee and comments;
    • scheduling;
    • locale variants;
    • references and revisions;
    • the unsaved-changes blocker;
    • the rule that Ctrl/⌘+S never publishes a live document;
    • the conflict banner;
    • the saved-status texts;
    • restore.

Core (lib/doc-editor.ts). Every change here is additive.

  • The store tracks baseline, writeState and availableActions.
  • transport.save receives patch, and the store adopts any result that has state. The status comes from the change set before and after the save.
  • New methods: act(action, input?), change(doc) and transport.load.
  • docPatch moves here from ui-react, which re-exports it.

API. getDocEditorMeta also returns state and availableActions, so the editor has them before its first save.

S1, closed. s1-primitives-boundary.test.ts now:

  • forbids FieldInput in every admin route;
  • requires <DocForm in the edit route;
  • forbids the edit route from calling canReadField, canWriteField or isFieldVisible.

The old route fails all three.

The seam for 5c. Every save goes through form.submit and then handleSubmit. So validators that 5c attaches to DocForm's fields will gate every save with no change to the route.

Docs:

  • cms-ui-react.md has a new section, "With the core editor store", with a type-checked example.
  • The getDocEditorMeta rows are updated.
  • So is review-queue.md.

Changesets:

  • doc-editor-write-results.md (core minor);
  • doc-editor-meta-state.md (api minor);
  • admin-edit-route-doc-form.md (ui-react minor).

Breaking changes

None in published APIs. These admin changes are visible:

  • The header shows the strategy's state label and its decision buttons.
  • Save buttons follow availableActions. Under directStrategy, a non-publisher with content.write now sees Save, because their save commits. It used to say "Submit for review".
  • A server-side change after a save, such as a hook-computed field, shows without a reload.
  • Saves send a patch, so untouched fields aren't re-sent.

Merge record (for replay)

12e9e68: origin/main (R1a #22) into 5a. The one conflict was scripts/codemods/index.ts; both codemods were kept.

86198f9: 5b(i) #33 into 5b(ii).

Conflicts caused only by squash merges, in files the B/C stack didn't touch. Each took #33's side:

  • docs/tutorials/blog-cms.md
  • package.json
  • packages/ui-react/src/routes/index.tsx
  • cms.config.ts in eight examples and three starters

Real conflicts between the A and B/C stacks:

File Resolution
.claude/skills/payload-to-tanstack-cms/SKILL.md A's runtime-config wording, using readDocumentAs
app/base/src/model.ts A's side. 2c's hook changes are ported to collection-runtime.ts.
app/base/src/collection-runtime.ts (semantic) baseHooks used currentSession(), which 2c removed. They're ported to the args: afterChange({ id, operation, session }), afterDelete({ id, session }), postRead({ doc, access }).
app/prm/src/cms.config.ts defineCms(definition, { …, documentState: ownerDirectAgentReview({ autoApprove }) })
docs/api/cms-core.md A's definePlugin({ definition, runtime }) example with B/C's document.published check
docs/deployment/upgrading.md At the time, B/C kept §20–23 and A's sections became §24–27. The merge chain renumbers every step in merge order.
docs/migration/from-sanity.md both rows
docs/schema/building-pages.md (frontmatter) a combined description and keywords
packages/core/src/schema.ts, packages/core/tests/plugins.test.ts, packages/ui-react/src/routes/review.tsx union of imports and exports
scripts/codemods/index.ts all five codemods
cms.config.ts in seven starters A's side for collections (moved to cms.definition.ts), with imports unioned

After the merge, no stale currentSession, runWithSession or cmsVirtualRoutes remained.

355f800: 5a's 013cd74 into 5b(ii). The one conflict was upgrading.md.

How verified

GitHub Actions is out of billing, so everything ran locally.

Check Result
pnpm install --frozen-lockfile ok
test:ci (173 tasks) passes except the known @tanstack/cms-api:test:oxlint. Two no-non-null-assertion errors in the new store code are fixed in 26cdeaf.
test:dts clean (233)
test:dialects passes. This PR's commits leave every marker count unchanged.
test:definitions 26/26
test:scripts 100/100
E2E blog / base 30/30 (adds a workflow test) / 12/12
Characterization: core / libsql / postgres 37 / 83 / 120
Unit core doc-editor.test.ts 46 (15 new); a new api getDocEditorMeta test; ui-react 124, including the tightened S1 test

The new E2E test, examples/blog/e2e/editor.spec.ts, walks through:

  1. create and publish: Unpublished → Published;
  2. a draft edit, then Discard draft restores the live title;
  3. an author submits: Pending Review, with no Approve button for the author;
  4. an editor clicks Approve in the editor: Published.

Assumptions (tasks 8–12 defaults)

  • State before the first save: the editor reads it from getDocEditorMeta, because documentWriteState is server-only.
  • The patch is computed once against the shared baseline.
  • Status comes from the change set before and after the save.
  • Decision buttons leave out the save actions and schedule. They use the strategy's labels.
  • act replaces the document and baseline, dropping unsaved edits, as discard did.
  • The loader refetch no longer syncs pendingVersion into the store.
  • Save buttons need both canWrite and an offered save action.
  • Save draft appears only for publishers, because runSave drafts only for them.
  • No new admin strings.

Divergence from plan

  • @tanstack/form-core is not in core. Where Q23 said the store should wrap the form, the store composes with it instead.
    • Wrapping would tie core's form-core version to ui-react's and change DocForm's API, with no added capability.
    • Q23's split still holds in substance: the form owns field state and validation, and the store owns concurrency, the pending overlay and save/act.
    • Wrapping can come later without a breaking change.
  • Autosave isn't added. The current editor has none, and save() can be called from a timer.
  • The admin no longer calls the legacy saveDoc or discardDraft ops. They stay, deprecated in 5a.

Merge chain (local verification, CI down)

This PR's commits are squashed into one commit on the linear merge chain. That commit holds this PR's own changes, resolved against every PR before it, with the integration rehearsal's fixes for this PR applied. Five conflicts, all where 5a's staged: false commits are already on the chain. The commit was replayed from 86198f9.

The chain tip's tree is exactly the integration rehearsal plus #46 (c4e6d7c), and the tip passes the full local suite. I simulated merging every PR in order, with a merge commit or a fast-forward at each step, and every step is clean. A plain squash of the next PR would conflict, because the squash commit isn't an ancestor of the next branch. To squash instead, first rebase the branch's one commit onto the new main; that rebase is always clean.

Open in Web Open in Cursor 

@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a0a6d16

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/cms-ui-react Minor
@tanstack/cms-api Minor
@tanstack/cms-core Minor
@tanstack/cms-client Minor
@tanstack/cms-cli Minor
@tanstack/cms-connect-atproto Patch
@tanstack/cms-migrate-wp Patch
@tanstack/cms-skills Patch
@tanstack/cms-media-s3 Minor
@tanstack/search-cms Patch
@tanstack/cms-store-libsql Minor
@tanstack/cms-store-postgres Patch
@tanstack/cms-ui-dom Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: TanStack/cms
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: d410e7c
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Free
  • Run ID: 06b9f1b7-9acb-49ac-b17c-daf76e318041
Commits

Reviewing files that changed from the base of the PR and between d410e7c and a0a6d16.

Files selected for processing: 17

  • .changeset/admin-edit-route-doc-form.md
  • .changeset/doc-editor-meta-state.md
  • .changeset/doc-editor-write-results.md
  • .changeset/doc-form-primitive.md
  • docs/agents/review-queue.md
  • docs/api/cms-ui-react.md
  • docs/api/routes-and-endpoints.md
  • docs/mcp/operations-registry.md
  • examples/blog/e2e/editor.spec.ts
  • packages/api/src/ops.ts
  • packages/api/tests/ops.test.ts
  • packages/core/src/index.ts
  • packages/core/src/lib/doc-editor.ts
  • packages/core/tests/doc-editor.test.ts
  • packages/ui-react/src/components/editor/doc-form.tsx
  • packages/ui-react/src/routes/edit.$collection.$id.tsx
  • packages/ui-react/tests/s1-primitives-boundary.test.ts

TanStack is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.

  • Ask an admin to upgrade

Open in CodeRabbit

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

…itor store (closes S1) (5b(ii)) (#42)

Chain step 22 of the linear merge chain onto main 3b4a112: this PR's own changes, resolved against the PRs before it in the merge order.

Co-authored-by: jherr <jherr@pobox.com>
@jherr
jherr force-pushed the cursor/admin-edit-route-d21e branch from 2767e37 to a0a6d16 Compare November 6, 2026 15:10
@jherr
jherr merged commit 0a238b0 into main Nov 6, 2026
@jherr
jherr deleted the cursor/admin-edit-route-d21e branch November 8, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants