Skip to content

fix: change editableTypes from Set to Map with resolved field objects#2490

Merged
christianhg merged 1 commit intomainfrom
refactor/editable-types-map
Apr 10, 2026
Merged

fix: change editableTypes from Set to Map with resolved field objects#2490
christianhg merged 1 commit intomainfrom
refactor/editable-types-map

Conversation

@christianhg
Copy link
Copy Markdown
Member

@christianhg christianhg commented Apr 10, 2026

The container rendering pipeline needs to know which fields inside a container are editable, not just whether a type is editable. Today editableTypes is a Set<string> that only answers "is this type editable?" This forces every call site to re-walk the schema to find the actual array field definition.

This changes editableTypes to a Map<string, Array<ChildArrayField>> where the key is the scoped type name (e.g., 'code', 'table.row.cell') and the value is the fully resolved array field definitions (with name and of scope).

A new resolveEditableTypes(schema, renderers) function walks the schema once at renderer registration time and returns the complete Map. Every call site that previously needed a schema walk now does a direct Map lookup:

const arrayField = editableTypes.get(scopedName)?.[0]

This eliminates resolveEditableField, resolveNamedArrayField, resolveChildArrayField, and getEditableTypePaths as separate concepts. It also removes the scope parameter that was threaded through getNodeChildren and its 10+ callers (modify.ts, is-leaf.ts, get-node.ts, get-child-field-name.ts, get-children.ts). The scope chain existed solely to feed into the runtime schema walk, which no longer happens.

modify.ts functions (modifyDescendant, modifyChildren, modifyLeaf) now take Editor directly instead of Editor | Node with schema and editableTypes as separate parameters. The only caller is apply-operation.ts which always passes the editor, so the isEditor checks and new Map() fallbacks were dead code.

editable-types.ts owns the full concept: the EditableTypes type, the ChildArrayField type, and the resolveEditableTypes function that produces the Map from a schema and renderer set.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment Apr 10, 2026 1:12pm
portable-text-example-basic Ready Ready Preview, Comment Apr 10, 2026 1:12pm
portable-text-playground Ready Ready Preview, Comment Apr 10, 2026 1:12pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 10, 2026

🦋 Changeset detected

Latest commit: 4304a45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@portabletext/editor Patch
@portabletext/plugin-character-pair-decorator Patch
@portabletext/plugin-emoji-picker Patch
@portabletext/plugin-input-rule Patch
@portabletext/plugin-markdown-shortcuts Patch
@portabletext/plugin-one-line Patch
@portabletext/plugin-paste-link Patch
@portabletext/plugin-sdk-value Patch
@portabletext/plugin-typeahead-picker Patch
@portabletext/plugin-typography Patch
@portabletext/toolbar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

📦 Bundle Stats — @portabletext/editor

Compared against main (6e1e9baf)

@portabletext/editor

Metric Value vs main (6e1e9ba)
Internal (raw) 760.4 KB -2.1 KB, -0.3%
Internal (gzip) 143.8 KB -367 B, -0.2%
Bundled (raw) 1.35 MB -2.1 KB, -0.1%
Bundled (gzip) 304.5 KB -392 B, -0.1%
Import time 96ms +1ms, +0.9%

@portabletext/editor/behaviors

Metric Value vs main (6e1e9ba)
Internal (raw) 467 B -
Internal (gzip) 207 B -
Bundled (raw) 424 B -
Bundled (gzip) 171 B -
Import time 3ms +0ms, +1.2%

@portabletext/editor/plugins

Metric Value vs main (6e1e9ba)
Internal (raw) 2.5 KB -
Internal (gzip) 910 B -
Bundled (raw) 2.3 KB -
Bundled (gzip) 839 B -
Import time 8ms +0ms, +1.0%

@portabletext/editor/selectors

Metric Value vs main (6e1e9ba)
Internal (raw) 60.5 KB -
Internal (gzip) 9.5 KB -
Bundled (raw) 56.9 KB -
Bundled (gzip) 8.7 KB -
Import time 6ms +0ms, +0.7%

@portabletext/editor/utils

Metric Value vs main (6e1e9ba)
Internal (raw) 24.2 KB -
Internal (gzip) 4.7 KB -
Bundled (raw) 22.2 KB -
Bundled (gzip) 4.4 KB -
Import time 6ms +0ms, +0.9%

🗺️ . · ./behaviors · ./plugins · ./selectors · ./utils · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@christianhg christianhg force-pushed the refactor/editable-types-map branch from a2c7255 to f860449 Compare April 10, 2026 10:49
@christianhg christianhg force-pushed the refactor/editable-types-map branch from f860449 to 0db631e Compare April 10, 2026 11:06
@christianhg christianhg force-pushed the refactor/editable-types-map branch from 0db631e to f71c1c3 Compare April 10, 2026 11:12
@christianhg christianhg force-pushed the refactor/editable-types-map branch from f71c1c3 to 761d6b5 Compare April 10, 2026 11:14
@christianhg christianhg force-pushed the refactor/editable-types-map branch from 761d6b5 to 84889fa Compare April 10, 2026 11:34
@christianhg christianhg force-pushed the refactor/editable-types-map branch from 84889fa to bbc6d21 Compare April 10, 2026 11:42
@christianhg christianhg force-pushed the refactor/editable-types-map branch from d1ef609 to 4f696a7 Compare April 10, 2026 12:41
@christianhg christianhg force-pushed the refactor/editable-types-map branch from 4f696a7 to 992c898 Compare April 10, 2026 12:47
@christianhg christianhg force-pushed the refactor/editable-types-map branch from 992c898 to a8d68b0 Compare April 10, 2026 12:59
@christianhg christianhg force-pushed the refactor/editable-types-map branch from a8d68b0 to 3861ef2 Compare April 10, 2026 13:04
@christianhg christianhg force-pushed the refactor/editable-types-map branch from 3861ef2 to 97739a1 Compare April 10, 2026 13:08
…string>>`

The map key is the scoped type name and the value is an array of
editable field names. This prepares for explicit field declaration
in the renderer API, where consumers declare which fields are
editable instead of relying on the "first array field" convention.

Map values are empty arrays for now. The renderer API will populate
them with field names when it lands.
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.

1 participant