Skip to content

fix(cms): stop recursive schema types from freezing the site editor - #7899

Merged
guitavano merged 2 commits into
mainfrom
guitavano/cev-deco-crash
Oct 13, 2026
Merged

guitavano merged 2 commits into
mainfrom
guitavano/cev-deco-crash

Conversation

@guitavano

@guitavano guitavano commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What is this contribution about?

After a storefront bumps @decocms/* from 7.71.x to 7.78.x, its regenerated .deco/meta.gen.json emits recursive commerce types as named definitions. Earlier versions inlined them. In these definitions, …/commerce.ts@Product references itself 6 times (for example isVariantOf.hasVariant: Product[] and isRelatedTo), and @ImageObject and @VideoObject reference each other. Opening the Site Editor on such a project froze the browser tab: first Chrome's "Page unresponsive" dialog, then "Aw, Snap! Error code 5" (out of memory).

The cause is in buildProperty in resolve-schema.ts. Its seen cycle guard only gated union branch materialization. Plain structural descent (nested properties and array items) re-expanded every re-entered $ref until MAX_STRUCTURE_DEPTH (32). Array items.$ref was resolved before the recursive call, so its key never reached seen. With 3 or more self-references per level, the expansion never finishes in practice. The section list runs resolveSchema per row to show the required-field dot, so the hang started as soon as the panel opened.

Changes:

  • cyclicUnion → cyclicRef. When a $ref is already on the current path, buildProperty still emits the node (and a selector's option list) but skips its nested properties/items.
  • Array items are passed to buildProperty with their $ref intact, so the guard sees the item type. The {{…}} titleBy is still read from the resolved definition.
  • sectionHasMissingRequiredField uses cachedResolveSchema, so a page with many product shelves resolves each section type once.

How did you verify your code works?

  • Added resolveSchema – recursive data types (hang guard) to resolve-schema.test.ts. It uses a schema with the same structure as Product/ImageObject/VideoObject and asserts that the cycle is cut at the re-entered Product, both through an array item and through a nested object's array. On the previous code this test never finishes (killed after 30s); with the fix it passes.
  • Ran the real resolveSchema over every manifest block (227) of an affected project's meta.gen.json, before and after its dependency bump:
    • pre-bump meta: ~70–90ms total, with and without this change.
    • post-bump meta, old code: hung for more than 60s on the first section with a product loader.
    • post-bump meta, this change: ~0.6s total, at most ~130ms for a single section.
  • bun test src/components/sections-editor/: 865 pass. bun run verify: 10883 pass, 0 fail. fmt:check and lint are clean.

Screenshots/Demonstration

No visual change. The editor now opens instead of freezing.

How to Test

  1. Open the Site Editor for a project whose .deco/meta.gen.json was generated by @decocms/blocks-cli 7.78.x and that has product shelf sections.
  2. Open the Content panel and drill into a product shelf section.
  3. Expected: the panel loads and the fields render. Where Product refers back to itself, the field shows as an object with no nested fields instead of expanding again.

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


Summary by cubic

Fixes the Site Editor freezing on schema types that reference themselves recursively, which started after a @decocms/* bump regenerated .deco/meta.gen.json with named recursive definitions like Product (self-referencing via isVariantOf.hasVariant: Product[]) and mutual references between ImageObject and VideoObject.

The cycle guard previously only gated union branch materialization, so plain property and array item descent re-expanded every re-entered $ref until the depth cap — enough to hang the browser tab when the section list resolved its schemas.

Changes

  • $refs already on the current path now emit the node but skip nested properties and items, for arrays and unions alike.
  • Array item $refs are passed through to the cycle guard instead of being resolved first.
  • The section list's required-field check now uses cachedResolveSchema, so each section type resolves once per page.
  • Regression test covers the Product/ImageObject/VideoObject shape, registered through the manifest so it exercises the full section resolution path; it never finished on the previous code and passes now.

Written for commit 876e2bc. Summary will update on new commits.

View guided diff Turn on auto-fix

Newer blocks-cli emits recursive commerce types as named definitions
(Product → isVariantOf.hasVariant: Product[], ImageObject ↔ VideoObject).
resolveSchema's cycle guard only covered union branches, so plain
properties and array items re-expanded each re-entered $ref up to
MAX_STRUCTURE_DEPTH, which hung the tab when the section list resolved
its schemas. Skip the nested schema of a $ref already on the path, pass
array items' $ref through so the guard sees it, and cache the schema the
section list resolves per row.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the claude PR authored by a coding agent label Oct 13, 2026
@guitavano
guitavano merged commit ac12a70 into main Oct 13, 2026
33 checks passed
@guitavano
guitavano deleted the guitavano/cev-deco-crash branch October 13, 2026 21:48
decocms Bot pushed a commit that referenced this pull request Oct 13, 2026
PR: #7899 fix(cms): stop recursive schema types from freezing the site editor
Bump type: patch

- decocms (apps/api/package.json): 4.477.0 -> 4.477.1
- @decocms/native (apps/native/package.json): 4.477.0 -> 4.477.1

Deploy-Scope: web
guitavano added a commit that referenced this pull request Oct 14, 2026
…pened (#7903)

#7899 stopped resolveSchema from re-expanding a `$ref` already on the
path, which fixed the hang on recursive commerce types but left the cut
node without `properties`/`items`. A recursive menu type
(`Item.children: Item[]`) therefore listed its child items but opened
each one as an empty form.

Mark the cut node with `recursiveRef` and expand it one level on demand
(`resolveSchemaRef` + cached `expandRecursiveSchema`) when renderField or
ArrayField reaches it, so the hang guard stays while nested levels remain
editable.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
tlgimenes added a commit that referenced this pull request Oct 15, 2026
… (A9)

The PO asked for main's recursive-schema behaviour, for v7 and v8 sites
alike. Remove MAX_RECURSIVE_REF_REPEATS, the per-path repeat count and the
array-items `$ref` pass-through that came with it, and the tests that
pinned three levels. The following cherry-picks bring main's own fix
(#7899, #7903): a re-entered `$ref` is cut and expanded on demand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
tlgimenes pushed a commit that referenced this pull request Oct 15, 2026
…7899)

* fix(cms): stop recursive schema types from freezing the site editor

Newer blocks-cli emits recursive commerce types as named definitions
(Product → isVariantOf.hasVariant: Product[], ImageObject ↔ VideoObject).
resolveSchema's cycle guard only covered union branches, so plain
properties and array items re-expanded each re-entered $ref up to
MAX_STRUCTURE_DEPTH, which hung the tab when the section list resolved
its schemas. Skip the nested schema of a $ref already on the path, pass
array items' $ref through so the guard sees it, and cache the schema the
section list resolves per row.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* test(cms): register the recursive-type fixture through a manifest $ref

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit ac12a70)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
tlgimenes pushed a commit that referenced this pull request Oct 15, 2026
…pened (#7903)

#7899 stopped resolveSchema from re-expanding a `$ref` already on the
path, which fixed the hang on recursive commerce types but left the cut
node without `properties`/`items`. A recursive menu type
(`Item.children: Item[]`) therefore listed its child items but opened
each one as an empty form.

Mark the cut node with `recursiveRef` and expand it one level on demand
(`resolveSchemaRef` + cached `expandRecursiveSchema`) when renderField or
ArrayField reaches it, so the hang guard stays while nested levels remain
editable.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 6d8748d)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
tlgimenes added a commit that referenced this pull request Oct 15, 2026
Brings in 114 commits from main, including #7909 (PATCH decofile `expect`
fingerprints, 409 block-conflict, value-by-value block merge on sync) and
guitavano's #7899/#7903.

One conflict, in apps/api/src/decofile/commit-coalescer.ts: this branch
moved the gen-artifact regeneration and the commit message into
gen-artifact.ts (shared with hosted publish), while #7909 changed the
message to name only the accepted patches. The resolution keeps the shared
helpers and passes them #7909's accepted `set`/`del`, so the legacy and
Fast Preview write path behaves exactly as on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
tlgimenes added a commit that referenced this pull request Oct 15, 2026
…ection

Brings in fold/v8-api, which now carries origin/main (114 commits),
including #7909 and #7918 (section forms start from a known version, saves
send `expect`, a stale save is refused with 409 and replayed or reloaded).

Conflicts resolved:
- use-save-block.ts: main's Fast Preview save (`base` -> `expect`, rebase
  on 409, BlockConflictError, no rollback on a conflict, `written`) moves
  into this branch's `writeLegacy`; the content-protocol path and SaveGuard
  stay as they were. `mutate`/`mutateAsync` keep main's `withBase` default
  and the hook keeps `reportError`.
- sections-editor.tsx: both form reloads stay (the content-epoch reload for
  discards/publishes and #7909's `reloadStaleForm`); main's form-base
  tracking, three-way merge, section following and retry-once are kept;
  failed saves use this branch's `reportError`.
- serve-save-error.ts: a BlockConflictError's own message (#7909's copy) is
  the toast headline on every backend, with no Details line.
- resolve-schema.ts and its cache test: #7899/#7903 were already
  cherry-picked here; this branch's lazy-block handling and A9 test stay.
- cms-header-actions.tsx / cms-panel-state.ts: main dropped
  cmsHeaderButtonLabels; the hosted header helpers stay.
- playwright.config.ts: both env additions (hosted env, GraphQL stub URL,
  BOARD_TRANSITION_SETTLE_SECONDS).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016ZsmzpZ2zahRBoATBb2tBu
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