Skip to content

feat(core,ui-react): client-side, schema-derived validation in DocForm and the admin editor (5c) - #45

Merged
jherr merged 1 commit into
mainfrom
cursor/client-validation-d21e
Nov 6, 2026
Merged

jherr merged 1 commit into
mainfrom
cursor/client-validation-d21e

Conversation

@jherr

@jherr jherr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements cms-refactor-plan.md § Phase 5 (5c): client-side, schema-derived validation.

Merge chain: step 23 of 24. Base: main. Merge it right after #42. The branch is main 3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit 095d69c (tree bf07ae4).

What

  • Core: schemaIssues(collection, doc), a new client-safe export (lib/validation.ts).

    • It fills derived fields and runs the same schemaFor parse the server's write path runs.
    • It checks required on the fields that showWhen shows. That walk moved out of the server's checkFieldRules into this shared module, so client and server run one implementation. checkFieldRules keeps its issue order and messages.
    • A parity test sends 14 documents through real writes and checks that schemaIssues returns exactly the server's paths and messages.
  • DocForm / useDocForm.

    • Validators: every rendered, writable field gets an onBlur validator. TanStack Form also runs it on submit, so a submit that fails validation never reaches onSubmit, and submit() resolves false.
    • Server errors: errors from the server still take precedence over the form's own messages.
    • Opt-outs: validate={false} turns the schema checks off. fieldValidators: { name: fn | false } overrides a single field, and fn receives that field's schemaError.
    • Bespoke forms: the API returns fieldErrors and validatorsFor(name).
  • Admin edit route. It gets validation through DocForm with no extra wiring. A blocked save shows the existing "Fix the highlighted fields" alert and sends nothing.

  • Fixed on the way, both caught by the base E2E:

    • FieldInput rendered its control at a different depth with and without an error. So when an error appeared on blur, React remounted the input the user had just moved into, which lost a typed array-item name.
    • "Blur" now means focus leaving the field, not moving between inputs inside an array or group.

    Each fix has a unit test that fails with the fix reverted.

  • Docs and changesets:

    • schema-issues.md (core, minor);
    • doc-form-validation.md (ui-react, minor).

Breaking changes

None in the APIs. Two things change visibly:

  • The admin editor now blocks a save that fails schema checks, before anything is sent to the server.
  • FieldInput always wraps an enabled control in a <div>.

How verified

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

Check Result
pnpm install --frozen-lockfile ok
test:ci (174 tasks) passes except the known @tanstack/cms-api:test:oxlint
test:dts clean (234)
test:dialects passes; the inventory is identical before and after this branch
test:definitions 26/26
test:scripts 100/100
E2E blog 31/31. The new test makes a blocked save with an inline error and checks nothing was sent, then fixes the field and saves successfully.
E2E base 12/12
Characterization: core / api / libsql / postgres 37 / 21 / 83 / 120
Package suites: core / api / ui-react 709 / 217 / 133

Assumptions (conservative defaults where the plan gives none)

  • Custom validate stays server-side. That covers functions and Standard Schemas, which may use server-only code or be async. The docs show how to run such a rule on the client early with fieldValidators.
  • Unwritable and unrendered fields aren't checked, because the user couldn't fix them.
  • No on-change validation. An error clears on the next blur or submit.
  • preValidate hooks aren't visible to the client. A hook that fills a required value would make the client stricter than the server for that field. None of the examples do that, and the opt-outs cover it.
  • fieldValidators still run when validate={false}.

Divergence from plan

  • FieldInput changed outside DocForm: an enabled control is now always wrapped.
  • checkFieldRules was refactored to share the showWhen-required walk.

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 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: 4c69bb9

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-core Minor
@tanstack/cms-api Minor
@tanstack/cms-cli Minor
@tanstack/cms-client 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: 0a238b0
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Free
  • Run ID: 8b351459-8ab6-4092-b074-fa3341f14dc2
Commits

Reviewing files that changed from the base of the PR and between 0a238b0 and 4c69bb9.

Files selected for processing: 16

  • .changeset/doc-form-validation.md
  • .changeset/schema-issues.md
  • docs/api/cms-core.md
  • docs/api/cms-ui-react.md
  • docs/schema/collections-and-fields.md
  • examples/blog/e2e/editor.spec.ts
  • packages/core/src/index.ts
  • packages/core/src/lib/validation.ts
  • packages/core/src/server/store/internal.ts
  • packages/core/tests/validation.test.ts
  • packages/ui-react/src/components/editor/doc-form.tsx
  • packages/ui-react/src/components/editor/field-input.tsx
  • packages/ui-react/src/lib/editor-errors.ts
  • packages/ui-react/src/primitives.ts
  • packages/ui-react/src/routes/edit.$collection.$id.tsx
  • packages/ui-react/tests/doc-form.test.tsx

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

cursor Bot pushed a commit that referenced this pull request Nov 6, 2026
…n rehearsal

Co-authored-by: jherr <jherr@pobox.com>
@cursor
cursor Bot force-pushed the cursor/admin-edit-route-d21e branch from 26cdeaf to 2767e37 Compare November 6, 2026 14:50
@cursor
cursor Bot force-pushed the cursor/client-validation-d21e branch from 66b3f69 to 095d69c Compare November 6, 2026 14:50
@cursor
cursor Bot changed the base branch from cursor/admin-edit-route-d21e to main November 6, 2026 14:59
…m and the admin editor (5c) (#45)

Chain step 23 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/client-validation-d21e branch from 095d69c to 4c69bb9 Compare November 6, 2026 15:10
@jherr
jherr merged commit 3c5e36a into main Nov 6, 2026
1 check passed
@jherr
jherr deleted the cursor/client-validation-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