Skip to content

fix: infer image, cta, and rtf types in local-editor#1247

Merged
benlife5 merged 7 commits into
2026-custom-components-templatesfrom
local-editor-types
Jun 29, 2026
Merged

fix: infer image, cta, and rtf types in local-editor#1247
benlife5 merged 7 commits into
2026-custom-components-templatesfrom
local-editor-types

Conversation

@benlife5

Copy link
Copy Markdown
Contributor

We infer the types of entity document fields in the local-editor, but RTF, Image, and CTA fields were just being picked up as generic objects. This means that they wouldn't show up in the correct dropdowns (particularly for createItemSource). This checks for their subfields and narrows the type if there's a match.

Also removes the c_ prefix when generating the display name.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 80699899-3199-4dc7-b079-fbef9f3764c4

📥 Commits

Reviewing files that changed from the base of the PR and between c1feb58 and 11a679c.

📒 Files selected for processing (3)
  • packages/visual-editor/src/vite-plugin/local-editor/data.ts
  • packages/visual-editor/src/vite-plugin/local-editor/entityFields.test.ts
  • packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/visual-editor/src/vite-plugin/local-editor/data.ts
  • packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts

Walkthrough

inferEntityFields now accepts either a single snapshot document or an array of snapshot documents, iterating over all entries and merging inferred field nodes. A new inferStructuredObjectType helper and shape-checking predicates detect rich text v2, image, and CTA object shapes, assigning specific typeRegistryId values instead of the generic "type.object". toDisplayName strips the "c_" prefix. getLocalEditorDocument now reads every snapshot JSON for the selected template and passes the full array to inferEntityFields. A new Vitest suite covers single-document structured-type inference, nested image detection, and multi-document schema merging.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: inferring image, CTA, and RTF types in the local editor.
Description check ✅ Passed The description is directly related to the changeset and mentions the same field type inference and display-name update.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch local-editor-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/visual-editor/src/vite-plugin/local-editor/data.ts`:
- Around line 115-127: The template-sibling snapshot loading in
getLocalEditorDocument is too brittle because readJsonFile errors from
non-selected documents can abort the whole request. Update the templateDocuments
collection logic to handle parse failures per sibling snapshot, emit a
diagnostic for the malformed file, and continue building entityFields from only
the snapshots that were read successfully. Keep the selected document path
unchanged and use the existing getLocalEditorDocument, readJsonFile, and
inferEntityFields flow to locate the fix.

In `@packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts`:
- Around line 218-223: The isRichTextValue predicate is too broad and is
reclassifying unrelated objects as rich text. Tighten the check in
isRichTextValue so it only returns true for the actual rich-text shape, such as
requiring a json object with the expected rich-text structure (for example
json.root) or a valid html string. Keep the change localized to isRichTextValue
in entityFields.ts so the type inference no longer promotes false positives to
type.rich_text_v2.
- Around line 277-279: The toDisplayName helper only strips the first “c_” from
the full path, so nested custom fields can still display incorrectly or lose
non-prefix matches. Update toDisplayName in entityFields.ts to process each path
segment separately, removing the “c_” prefix from every segment before
formatting the display name, and keep the rest of the path-to-label conversion
logic unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9128723e-fe2d-43ed-96c2-5cf9f4821fb8

📥 Commits

Reviewing files that changed from the base of the PR and between d605f45 and c1feb58.

📒 Files selected for processing (3)
  • packages/visual-editor/src/vite-plugin/local-editor/data.ts
  • packages/visual-editor/src/vite-plugin/local-editor/entityFields.test.ts
  • packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts

Comment thread packages/visual-editor/src/vite-plugin/local-editor/data.ts Outdated
Comment thread packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts Outdated
Comment thread packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts Outdated
@benlife5 benlife5 marked this pull request as ready for review June 29, 2026 14:25
Comment thread packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts Outdated
Comment thread packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts Outdated
Comment thread packages/visual-editor/src/vite-plugin/local-editor/entityFields.ts Outdated
mkilpatrick
mkilpatrick previously approved these changes Jun 29, 2026

const isCtaValue = (value: Record<string, unknown>): boolean => {
return typeof value.label === "string" && typeof value.link === "string";
return (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when this returns false? Anything detrimental?

Would it be better to do linkType && (label || link)? Or even JUST linkType?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh yeah linkType && (label || link) is probably good. If it doesn't match, then it doesn't show up in type.cta dropdowns... We might eventually need to pull the full schema so that the local-editor is more functional with all data types, but this will get us the main types for now

@benlife5 benlife5 merged commit 812f513 into 2026-custom-components-templates Jun 29, 2026
15 of 16 checks passed
@benlife5 benlife5 deleted the local-editor-types branch June 29, 2026 15:43
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.

4 participants