Repository navigation
feat(cms): project switch to write section defaults only in new blocks - #8390
Closed
aka-sacci-ccr wants to merge 6 commits into
Closed
aka-sacci-ccr wants to merge 6 commits into
aka-sacci-ccr wants to merge 6 commits into
Conversation
3 of 4 tasks
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
force-pushed
the
feat/cms-persist-defaults-setting
branch
from
November 6, 2026 19:26
94e55c1 to
77da486
Compare
…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]>
- 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]>
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.
What is this contribution about?
Opening a section's form in the CMS fills every missing schema
@defaultinto 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: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:
defaultsOnCreateOnlytoSchemaForm, andRootSchemaFormthen hands the fields the stored value instead of a copy filled with defaults. It doesn't even compute that fill.null): the edit creates it with only that field, not its other defaults.CreateOnlyContextis on only under an opted-in form, so fields fill only what they create:type-discriminated union value (e.g. an item of a list of cards), filled from its branch;SchemaFormWithoutDefaultSeeding). An absent number now shows an empty input instead of a0nothing 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 isuse-apply-named-rule.test.tsx, which this PR doesn't touch. It is flaky onmaintoo: it failed 2 of 10 runs there, and it passed 5 of 5 isolated reruns on this branch.tsc --noEmitpasses forapps/webandpackages/shared.ct/tests/defaults-on-create-only.ct.tsx(7 cases, usingtoEqualso a leaked default fails):TitleandColumnsshow empty, nothing is written, and editingSubtitlesaves exactly the stored value plus it;nullobject writes only that edit;bun run test:ct): 273 passed.withDefaultsForNew: a new block, an array item, and atype-discriminated union value getting its branch's defaults (an existing one still gets only its discriminator);seedMatcherRulewith and withoutwithDefaults;buildSectionBlockFromCatalogEntrywith and withoutmeta;Screenshots/Demonstration
How to Test
Review Checklist
🤖 Generated with Claude Code