Repository navigation
feat(ui-react): DocForm, a schema-driven TanStack Form editor primitive in /primitives (5b(i)) - #33
Merged
Merged
Conversation
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Next included review available in 59 minutes. View limit details
TanStack is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.
|
🦋 Changeset detectedLatest commit: ee4f37f The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
cursor
Bot
force-pushed
the
cursor/form-editor-primitive-d21e
branch
from
November 6, 2026 14:50
1912728 to
99dea28
Compare
cursor
Bot
force-pushed
the
cursor/field-renderers-d21e
branch
from
November 6, 2026 14:50
ff0c8c7 to
8c41fab
Compare
jherr
force-pushed
the
cursor/form-editor-primitive-d21e
branch
from
November 6, 2026 15:07
99dea28 to
ee4f37f
Compare
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.
This PR implements the first half of cms-refactor-plan.md § Phase 5, 5b (item 10a): exporting the TanStack Form editor primitive. The second 5b PR rebuilds the admin edit route on it, after 5a.
Merge chain: step 9 of 24. Base:
main. Merge it right after #32. The branch ismain3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit99dea28(treeed1e9ba).What
@tanstack/cms-ui-react/primitives:DocForm,useDocForm,docPatch(src/components/editor/doc-form.tsx)<DocForm collection="post" … />resolves the name through core'scollections()registry (requireCollection), like the 1b primitives. An unknown name throws.showWhenare left out, andshowWhenis evaluated against the live values.access={{ session, doc }}, fields the session can't read are hidden and fields it can't write are locked. These are the same rules the admin route and the server use.@tanstack/react-form, which is already a dependency. Each field is aform.Field, so 5c's validators and blur metadata can attach without an API change.value/onChangeordefaultValue. Whenvaluechanges from outside, the form adopts it without echoing it back throughonChange.onSubmit(patch, { doc, baseline, meta }).submit(meta)argument.save().error. Otherwise the submitted doc becomes the new baseline, unless the parent controlsbaseline.renderers?: CmsRenderers(onDocFormanduseDocForm). This is the app's renderers module from feat(core, ui-react)!: field inputs and cells move out of the config into the renderers module (R2 fields) #32 (defineRenderers({ inputs, fieldTypes })). It's passed to everyFieldInput, nested fields included. Without it,FieldInputfalls back to the module bound throughcreateRoutes.fieldRenderers. A per-form override keyed by field type ({ number: Stepper }). An entry replaces the wholeFieldInputfor that type. It receivesFieldInputComponentProps,renderersincluded, so it can wrapFieldInput.fieldRenderers[field.type];input, fromrenderers, then the bound module;renderers, then the bound module;fieldRenderersstays next torenderers.fieldTypes. The two overlap only for custom types.fieldTypesrejects built-in types and replaces only the inner control underFieldInput's label and error.fieldRendererscovers built-in types too and replaces the whole field, for one form.FieldInput:errors(per field, e.g. a save'sfieldErrors),changedFields(the proposal highlight),store,relationSearch,disabled.useDocForm(options)returns{ form, collection, values, baseline, patch, dirty, submitting, error, submit, reset, setValue }.<DocForm form={api} />renders it, so a parent can place its buttons elsewhere and pass submit metadata (submit({ publish: true })).Starter usage. The
runtime-tablesstarter'sGeneratedRuntimeFormis rebuilt onDocForm, by collection name, with anonSubmit(patch, doc)prop. The seam test server-renders it.Docs.
cms-ui-reactreference has aDocFormsection: a props table,useDocForm,docPatch, two type-checked examples, and howrenderersandfieldRenderersrelate.collections-and-fields.mdhas a new guide section, "Editing documents in your own UI".CMS-INTEGRATION.mdis updated.Changeset.
.changeset/doc-form-primitive.md: minor for@tanstack/cms-ui-react. It's additive.How the admin edit route adopts it (second 5b PR, after 5a)
edit.$collection.$id.tsxstops mapping fields toFieldInputitself. Field filtering, write locks, the dirty compare and thefieldErrorswiring move intoDocForm.createDocEditorStorestays (Q23). It wraps the form with optimistic concurrency, the pending overlay and autosave.onSubmitcalls 5a's strategy action.{ doc, state, availableActions }drives the buttons and becomes the baseline. That PR is where@tanstack/form-coreenters core.How it closes the S1 leak. After the second PR, the edit route is composition only:
DocFormplus the core editor store and panels. The S1 test can then forbid the route from renderingFieldInputper field.Breaking changes
None in published packages. The props of the runtime-tables starter's own
GeneratedRuntimeFormchange, but that starter is unpublished and only its seam test used the component.How verified
CI is down because GitHub Actions is out of billing, so I verified locally, in the post-batch-3 state. In a scratch branch, I rebased #25 → #28 → #31 → #32 → 5b(i) onto #24's main-based head
2850c54withgit rebase --onto 2850c54 e126e12. All 44 commits replayed with no conflicts.pnpm install --frozen-lockfile: ok.pnpm test:ci(174 tasks, no cache): passes except the known@tanstack/cms-api:test:oxlintfailure, which main also has.test:dts: clean, 226.d.tsfiles.test:dialects: passes. It reportsreadDocument (test)rising from 244 to 248 above the baseline. That count is already on main, frompackages/core/tests/slow-hooks.test.tsin e568873 (feat(core)!: hooks as pre-commit consultation, events as announcement; drop legacy hook aliases #19).test:definitions: 26/26.test:scripts: 93/93.packages/ui-react/tests/doc-form.test.tsx.Assumptions (tasks 8–12 defaults)
The plan gives no default for these, so each takes the most conservative option.
DocFormanduseDocForm.null.onSubmitruns even when the patch is empty.baselineprop lets the parent own it.fieldRenderersapply to top-level fields only. Nested sub-fields still getrenderers.renderersgiven toDocFormwin over those given touseDocForm.access, every field is editable.errors.Record<string, unknown>internally, because TanStack Form's deep field-name types fail with TS2589 onJsonValue. The public API usesDocthroughout.Divergence from plan
@tanstack/form-coreisn't added to core yet. Q23 puts form-core in core. It arrives in the second 5b PR, where core's editor store wraps the form; adding it now would leave an unused dependency.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. No conflicts.
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 newmain; that rebase is always clean.