Skip to content

feat(cms): project switch to write section defaults only in new blocks - #8390

Closed
aka-sacci-ccr wants to merge 6 commits into
mainfrom
feat/cms-persist-defaults-setting
Closed

aka-sacci-ccr wants to merge 6 commits into
mainfrom
feat/cms-persist-defaults-setting

Conversation

@aka-sacci-ccr

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

Copy link
Copy Markdown
Contributor

What is this contribution about?

Opening a section's form in the CMS fills every missing schema @default into it, and saves them, either when the form opens or along with the first edit. That includes absent optional objects with defaulted children, and nested blocks such as loaders. The site runtime doesn't apply schema defaults, so a default written into an existing section can change what renders. In practice, editing one field of a section changed other fields nobody touched, and that reached production.

This adds a CMS project setting, Fill section defaults only in new sections (metadata.defaultsOnCreateOnly), off by default. It applies only to section forms:

  • the sections editor's section forms (the Preview and Content tabs);
  • a section variant's rule form;
  • the global section editor.

Pages, SEO, apps, CMS settings, loaders and page variant rules behave exactly as before, whether the switch is on or off.

With the switch on, in a section form:

  • The form edits the stored section itself. The caller passes defaultsOnCreateOnly to SchemaForm, and RootSchemaForm then hands the fields the stored value instead of a copy filled with defaults. It doesn't even compute that fill.
    • Opening writes nothing.
    • Editing field X saves exactly the stored section plus X. That holds inside an object or union value the section doesn't have yet (absent or null): the edit creates it with only that field, not its other defaults.
    • Every action that reads the form value (variant whole-block saves, hide or duplicate an item, make global, branch switches) works on the stored section.
  • What's created starts with its defaults. CreateOnlyContext is on only under an opted-in form, so fields fill only what they create:
    • a new array item;
    • a picked union branch, filled from that branch's own schema;
    • a new type-discriminated union value (e.g. an item of a list of cards), filled from its branch;
    • a field or section variant matcher;
    • A section added to a page is filled where it's inserted, and so is a global section created from the app editor.
  • Absent fields show their empty state. That is what the runtime receives, and the same trade-off the blog editors already make (SchemaFormWithoutDefaultSeeding). An absent number now shows an empty input instead of a 0 nothing stored, with the switch on or off. An absent boolean still shows off, even when its default is on. Showing the schema default as a hint could be a follow-up.

With the switch off: nothing written changes. Every fill point checks the switch, and the blog editors' forms never turn it on. The only visible difference is the empty number input above.

How did you verify your code works?

  • bun run verify: 13231 pass, 1 fail. The failure is use-apply-named-rule.test.tsx, which this PR doesn't touch. It is flaky on main too: it failed 2 of 10 runs there, and it passed 5 of 5 isolated reruns on this branch.
  • tsc --noEmit passes for apps/web and packages/shared.
  • ct/tests/defaults-on-create-only.ct.tsx (7 cases, using toEqual so a leaked default fails):
    • switch off → opening writes defaults (unchanged);
    • switch on → the absent Title and Columns show empty, nothing is written, and editing Subtitle saves exactly the stored value plus it;
    • switch on → a new array item starts with its defaults;
    • switch on → duplicating an item copies it as stored, without defaults;
    • switch on → the first edit inside an absent or a null object writes only that edit;
    • the blog's non-seeding form → adding an item writes no defaults.
  • Full component suite (bun run test:ct): 273 passed.
  • Unit tests:
    • withDefaultsForNew: a new block, an array item, and a type-discriminated union value getting its branch's defaults (an existing one still gets only its discriminator);
    • seedMatcherRule with and without withDefaults;
    • buildSectionBlockFromCatalogEntry with and without meta;
    • the switch.

Screenshots/Demonstration

How to Test

  1. In a Fast Preview or sandbox project, open Settings → CMS and turn on Fill section defaults only in new sections.
  2. Open a page whose section is missing a value its schema has a default for. The field shows empty, and nothing is saved or committed.
  3. Edit another field of that section, including one inside an object the section doesn't have yet. The save contains only that field.
  4. Duplicate or hide a list item. No defaults appear in the saved value.
  5. Add a new section or array item, or a global section from an app. It starts with its defaults.
  6. On a section variant, open its rule. Nothing is written; picking a new matcher starts it with its defaults.
  7. Page SEO, apps, CMS settings and page variant rules behave as before.
  8. Turn the switch off and open the section again. Today's behavior: the missing defaults are written.

Review Checklist

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

🤖 Generated with Claude Code

@github-actions github-actions Bot added the claude PR authored by a coding agent label Nov 6, 2026
Opening a block's form fills every missing schema `@default` into it — even
absent optional objects with defaulted children, and nested blocks such as
loaders — and saves them, on open or with the first edit. The site runtime
doesn't apply schema defaults, so a default written into an existing block
can change what renders: editing one field of a section changed others.

A new CMS project setting, `defaultsOnCreateOnly` (off by default; today's
behavior is unchanged), writes defaults only into what is being created:
- an existing block never gets a default for a field the user didn't touch;
  the form still shows defaults, but saves the stored value plus the user's
  changes (`unseedSchemaDefaults`, applied in `RootSchemaForm`);
- new sections, array items, picked branches and matchers, new global blocks,
  new pages (and their SEO) and a just-installed app still start with their
  defaults (`withDefaultsForNew` at each creation point; `newBlock` for forms
  that create their block);
- the page/site SEO forms now get the project, so they follow the setting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aka-sacci-ccr
aka-sacci-ccr force-pushed the feat/cms-persist-defaults-setting branch from 94e55c1 to 77da486 Compare November 6, 2026 19:26
@aka-sacci-ccr aka-sacci-ccr changed the title feat(cms): project switch to persist missing schema defaults when a form opens feat(cms): project switch to write schema defaults only in new blocks Nov 6, 2026
decobot and others added 3 commits November 9, 2026 12:32
…ults

With `defaultsOnCreateOnly` on, `RootSchemaForm` now hands the fields the
stored block rather than a copy filled with schema defaults, so nothing
needs stripping on save. That closes the paths that read the filled-in form
value and leaked defaults: whole-block saves of variant flags, hiding or
duplicating an array item, making a loader global, and inline-union branch
switches. An absent field shows its empty state, as the blog editors do.

Defaults now go only into what is created, and only with the switch on:
fields read `CreateOnlyContext` (array items, union branches, a first edit
of an absent value, field matchers); the editors read the project setting
(new sections, page matchers, new pages, app-editor sections). With the
switch off nothing changes — the blog's non-seeding forms included.

The SEO forms get the project through `DefaultsProjectContext` instead of a
full `sandbox`, and a SEO block switched on or retyped opens as `newBlock`.

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

Wrapping each editor's JSX in the provider re-indented both editors' render
trees; a thin outer component keeps their markup untouched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The switch is about editing sections, so only section forms opt in: the
sections editor's section forms (Preview and Content) and the global section
editor pass `defaultsOnCreateOnly` to `SchemaForm`. Pages, SEO, apps, CMS
settings, loaders and variant rules behave exactly as before, switch on or
off — which drops `newBlock`, `DefaultsProjectContext`, the editor wrappers,
page and app-editor seeding and the SEO/app "just created" state.

Inside an opted-in form, a value the stored block doesn't have is filled when
its first edit creates it (`updateField`), a picked union branch is filled
from that branch's own schema, and the form skips computing a fill it no
longer shows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aka-sacci-ccr aka-sacci-ccr changed the title feat(cms): project switch to write schema defaults only in new blocks feat(cms): project switch to write section defaults only in new blocks Nov 9, 2026
decobot and others added 2 commits November 9, 2026 14:44
- A section variant's rule form edits the stored rule, and a new matcher
  starts with its defaults, like the section form beside it.
- A global section created from the app editor starts with its defaults.
- A new type-discriminated union value starts with its branch's defaults,
  and a new object from its own object `default`.
- A stored `null` counts as absent: its first edit creates it with defaults.
- The switch's label, description and schema doc say it applies to sections.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With defaults-on-create-only on, the first edit inside an object or union
value the section didn't have filled its other `@default`s too, so editing
one field changed fields nobody touched. Only explicit creation (a new
section, item, branch or matcher) gets defaults now.

An absent number shows empty instead of a 0 that nothing stored.

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