Skip to content

fix(cms-studio): fix block-ref schema resolution for @decocms/start >=6.10 loaders - #4008

Merged
guitavano merged 11 commits into
mainfrom
cms-empty-form-bug
Jun 19, 2026
Merged

guitavano merged 11 commits into
mainfrom
cms-empty-form-bug

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two fixes for CMS Studio editing of sections that use loader props (e.g. SearchResult.page: ProductListingPage) in @decocms/start sites (bagaggio-tanstack, granadobr-tanstack).

resolve-schema.ts — extract resolveType from flat loader definitions

@decocms/start >=6.10 generates loader definitions with __resolveType.enum directly in properties (not nested under allOf). The allRefs block in buildProperty was falling back to the base64 definition key instead of the real resolveType (e.g. site/loaders/deliveryPromiseProductListingPage.ts), causing duplicate entries in the AnyOf dropdown.

Now also checks def.properties.__resolveType.enum directly, so the correct resolveType is extracted from flat definitions.

any-of-field.tsx — isolate loader breadcrumb from section breadcrumb

When a user drilled into an array item inside a loader config (e.g. selectedFacets → Item 1), onBreadcrumbChange propagated the loader-internal path (e.g. ['selectedFacets', '0']) to the outer section-editor breadcrumb. Since that path has no match in the section's top-level schema (SearchResult has page, sections, layout… not selectedFacets), the form showed ALL fields instead of just the focused item.

Module loaders now manage their breadcrumb state locally (loaderBreadcrumbs) so navigation inside a loader config stays self-contained and doesn't pollute the outer form.

Related

  • DECO-5295 — CMS Studio form vazio para seções inline (bagaggio-tanstack)
  • DECO-5296 — @decocms/start: gerar schemas de loaders para o admin CMS

Test plan

  • Open CMS Studio against bagaggio/granado (with @decocms/start 6.10.2)
  • SearchResult → Página de Listagem → loader dropdown shows correct name (not base64)
  • Click into selectedFacets → Item 1 → form shows only Key + Value, no surrounding section fields
  • CategoryBanner, Header, Footer (saved blocks) still work without regression

🤖 Generated with Claude Code


Summary by cubic

Fixes CMS Studio editing for loader props in @decocms/start 6.10+: correct resolve types, hidden fields honored, predictable breadcrumbs, and clearer labels (including Lazy and rich‑text); adds a rich‑text editor, safe link handling, and editing for resolved plain arrays from block‑refs. Addresses DECO-5295, DECO-5296, and DECO-5297.

  • Bug Fixes

    • Schema resolution: read properties.__resolveType.enum in flat loader defs to avoid base64 $ref fallback and duplicate AnyOf options.
    • Hidden block-ref fields: propagate hidden on all block-ref returns so hide: "true" props don’t show.
    • Breadcrumbs: module-loader unions use the field label; strip/add the outer crumb when drilling; match by label or key; disambiguate same‑label block‑refs by checking inner value keys; collapse/restore outer form correctly.
    • Labels and Lazy: use filename for loader dropdowns; label Section[] items by the inner section; ignore whitespace-only titles; strip HTML from rich‑text titles; use key as fallback; bind the unwrapped inner section and re-wrap on change.
    • Block-ref arrays: when a value is a resolved plain array, render it as an editable ArrayField.
    • Rich‑text links: validate URLs and block javascript:, data:, and vbscript:.
  • New Features

    • Rich‑text editor for rich-text, rich-text-inline, and html.

Written for commit c9649d3. Summary will update on new commits.

Review in cubic

JonasJesus42 and others added 9 commits June 19, 2026 11:52
…=6.10 loaders

Two fixes for CMS Studio editing of sections that use loader props
(e.g. SearchResult.page: ProductListingPage) in @decocms/start sites.

resolve-schema.ts — extract resolveType from flat loader definitions
@decocms/start >=6.10 generates loader definitions with __resolveType.enum
directly in properties (not nested under allOf). The allRefs block in
buildProperty was falling back to the base64 key instead of the real
resolveType, causing duplicate entries in the AnyOf dropdown. Now also
checks def.properties.__resolveType.enum directly.

any-of-field.tsx — isolate loader breadcrumb from section breadcrumb
When a user drills into an array item inside a loader config (e.g.
selectedFacets Item 1), onBreadcrumbChange was propagating the loader-
internal path (e.g. ['selectedFacets', '0']) to the outer section form.
Since that path has no match in the section's top-level schema, the form
showed all fields instead of the focused item. Module loaders now manage
their breadcrumb state locally (loaderBreadcrumbs) so navigation inside
a loader config stays self-contained.

Related: DECO-5295, DECO-5296

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…item

When user clicks an array item inside a loader config (e.g. selectedFacets
Item 1 in SearchResult), the surrounding section fields (Seções Adicionais,
Layout, etc.) were still visible because only the loader-internal breadcrumb
changed but the outer section breadcrumb remained reset.

Fix: when loaderBreadcrumbs becomes non-empty, also update the outer
breadcrumb to focus on the loader field key (e.g. 'page'). This collapses
the section form to show only the loader field, matching the old admin UX
where clicking an array item shows a clean focused view with just that
item's fields.

When loaderBreadcrumbs returns to empty (user goes back), restore the
outer breadcrumb to show the full section form again.

Also: add 'key' to getArrayItemLabel fallback keys so SelectedFacet items
show 'productClusterIds' instead of 'Item 1'.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Replace the local loaderBreadcrumbs state hack with proper breadcrumb
path threading through AnyOfField in module-loader mode.

schema-form-breadcrumb.ts: extend resolveActiveFieldKeyInScope to also
match block-ref fields (loaders) by key or label. This allows a path
like ['page', 'productClusterIds'] to resolve 'page' at the SearchResult
level, enabling the outer form to collapse to just the loader field.

any-of-field.tsx: in module-loader mode, strip the loader field's own
key from breadcrumbPath before passing to the nested SchemaForm, and
prepend it back in nestedOnBreadcrumbChange when propagating up.

Full navigation flow:
  user clicks 'productClusterIds' item in selectedFacets
  → ArrayField calls onBreadcrumbChange(['productClusterIds'])
  → AnyOfField prepends 'page': onBreadcrumbChange(['page', 'productClusterIds'])
  → section editor fieldBreadcrumbs = ['page', 'productClusterIds']
  → SearchResult SchemaForm resolves activeKey='page' (block-ref match)
     → shows only Página de Listagem, hides Seções Adicionais, Layout, etc.
  → AnyOfField strips 'page': nested SchemaForm gets ['productClusterIds']
  → loader SchemaForm resolves activeKey='selectedFacets' (item label match)
  → ArrayField shows only Key+Value for that item

Back navigation restores full form at each level.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…ropdown

When a loader's title is its file path (e.g. site/loaders/foo.ts), use
labelFromResolveType to derive a human-readable name from the filename
instead (e.g. DeliveryPromiseProductListingPage).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…adcrumb

B1 — @hide block-ref fields appeared in the form. resolve-schema.ts
buildProperty set 'hidden' only on the normal return path; the three
block-ref early returns didn't propagate it. So hidden loader/block-ref
props (e.g. SearchResult's tags/locationUser/stores, emitted by
@decocms/start as { anyOf:[Resolvable, loaderRef], hide:'true' }) leaked
into the UI as 'Select from saved'. Propagate hidden on all block-ref
returns. Added resolve-schema test.

B2 — breadcrumb showed the raw key 'page' instead of the field label.
any-of-field.tsx now prepends the field's display label (e.g. 'Página de
Listagem') to the breadcrumb in module-loader mode. resolveActiveFieldKey
matches both label and key, so navigation still resolves.

Related: DECO-5295

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
In a Section[] prop (e.g. SearchResult.sections), items are Lazy-wrapped
(`{ __resolveType: '.../Lazy.tsx', section: {...} }`). getArrayItemLabel
labelled them 'Lazy' instead of the inner section (e.g.
'BannerCarrouselDepartment'). Unwrap the Lazy wrapper before deriving the
label.

Related: DECO-5297

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…s fix)

Nested section array items (e.g. SearchResult.sections) are stored
Lazy-wrapped: { __resolveType: '.../Lazy.tsx', section: { <real section> } }.
AnyOfField resolved the inner section's SCHEMA (via moduleResolveTypeFromBlockData)
but bound the form against the OUTER wrapper, so every field rendered empty even
when the inner section had data (e.g. BannerCarrouselDepartment.carrousels).

Add lazyWrappedInner() and bind the unwrapped inner section as the form value,
re-wrapping into the Lazy shape on change. Verified against bagaggio-tanstack
/ultimas-unidades-escolar: carrousels/title now bind; save preserves the Lazy
wrapper + sibling props.

Related: DECO-5297

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…ion name

Some nested sections carry title: " " (a single space). getArrayItemLabel
returned it verbatim, so the array item showed a blank, hard-to-click row
(e.g. /bolsa-mochila SearchResult.sections → BannerCarrouselDepartment).

Treat whitespace-only strings as empty and fall through to the section name,
giving a visible label and a stable non-blank breadcrumb crumb.

Related: DECO-5297

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…ext field

Render data-only properties (present in page data but missing from _meta
schema) by inferring schemas from runtime values, with hint propagation
from the parent schema for format/title/description metadata. Add
dedicated RichTextField component for rich-text/html string formats.
Also fix breadcrumb path reset for module-loader unions and support
schema inference for plain-array block-ref values.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@guitavano
guitavano force-pushed the cms-empty-form-bug branch from 13371c9 to c965539 Compare June 19, 2026 15:53
guitavano and others added 2 commits June 19, 2026 14:17
…e data inference

- Strip HTML tags from rich-text fields in array item labels
- Disambiguate block-refs with same label using loose matching on value keys
- Render resolved plain arrays from block-ref fields as editable ArrayField
- Remove data-only field inference (schema is the source of truth)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…p, add tests

- Add isSafeLinkUrl() to block javascript:/data:/vbscript: URLs in rich-text link handler
- Reuse lazyWrappedInner() in array-item-display instead of inline detection
- Extract inferBlockRefArrayItemSchema() into testable pure module
- Add unit tests for link URL validation (11 cases) and array inference (8 cases)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@guitavano
guitavano merged commit 6901b59 into main Jun 19, 2026
14 checks passed
@guitavano
guitavano deleted the cms-empty-form-bug branch June 19, 2026 18:08
decocms Bot pushed a commit that referenced this pull request Jun 19, 2026
PR: #4008 fix(cms-studio): fix block-ref schema resolution for @decocms/start >=6.10 loaders
Bump type: patch

- decocms (apps/mesh/package.json): 3.36.6 -> 3.36.7

Deploy-Scope: web
tlgimenes pushed a commit that referenced this pull request Jul 16, 2026
…TS.md (#4475)

Mined ~300 merged PRs for the delta between the first PR proposal and the
work added before merge. The dominant shape: a first draft ships the happy
path, then a hardening pass (often a different engineer who takes over the
branch and merges — the vibecoder→engineer handoff) adds the same categories
every time. Encoded those 9 categories as an actionable first-pass checklist,
each citing a real PR (#4008, #4230, #4365, #4409, #4426, #4445, #4357, #4355,
#4449, #4350, #4373, #4416, #4446, #4461, #4134, #4469).

Covers: variant/edge-case handling, tenant/permission scoping, concurrency &
silent-data-loss, test-per-fix + invert-bug-tests + real-PG, dead-code/knip,
lifecycle symmetry + state reset, kill-switch/GC/git-exclude for risky infra,
input validation vs over-engineering, compile-time type-safety.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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