Skip to content

feat(portable-text): support container plugins via PTE catch-all renderers#12963

Draft
christianhg wants to merge 8 commits into
next-majorfrom
feat/portable-text-container-render
Draft

feat(portable-text): support container plugins via PTE catch-all renderers#12963
christianhg wants to merge 8 commits into
next-majorfrom
feat/portable-text-container-render

Conversation

@christianhg

Copy link
Copy Markdown
Member

Description

Studio's PortableText input has rendered text blocks, block objects, inline objects, list items and styles through four legacy PortableTextEditable callbacks (renderBlock, renderChild, renderListItem, renderStyle). With @portabletext/editor@7.2.0 the engine introduces a '*' catch-all sentinel for the defineX node registration factories — defineTextBlock({type: '*'}), defineBlockObject({type: '*'}), defineInlineObject({type: '*'}) — that fires on any _type not claimed by a more specific registration upstream.

Rewire Compositor to mount three such catch-alls through a NodePlugin and drop the four legacy callbacks from PortableTextEditable. The catch-all renders close over Compositor's locals directly; no new public Studio API.

This unlocks container plugins (lists, tables, blockquotes, …) for end users. A consumer can now register a container plugin on a Portable Text array and it composes naturally with Studio's chrome — the form-store, comments, presence and edit dialogs work for objects nested inside the container, and any _type the consumer doesn't claim falls through to Studio's catch-all renders.

Bonus: walk container-nested members in the form-store and resolve text blocks at any depth in the inline-comments helpers — both required for container plugins to compose with comments and the click-to-open dialog at arbitrary nesting depth.

Annotations stay on the legacy renderAnnotation callback (the PTE engine fires it regardless of the new pipeline).

What to review

  • packages/sanity/src/core/form/inputs/PortableText/Compositor.tsx — three new defineX({type: '*', render}) registrations replace editorRenderBlock + editorRenderChild. The text-block catch-all wraps editable children in the existing Style and ListItem components itself, since under defineTextBlock the engine no longer applies its default style/list-item wrapping. The block-object and inline-object catch-alls fall through to props.renderDefault(props) when the type isn't enumerated by the Sanity form-store walker (container-nested types declared in a container's of array).
  • packages/sanity/src/core/form/inputs/PortableText/Editor.tsx — drops the renderBlock, renderChild, renderListItem, renderStyle props.
  • packages/sanity/src/core/form/inputs/PortableText/hooks/usePortableTextMembers.tsx — replaces the depth-2 enumeration with a recursive collectFromBlockItem so objects inside container fields (list.items[].content[].image, …) get form member items.
  • packages/sanity/src/core/comments/utils/inline-comments/findTextBlockByKey.ts plus the two helpers that use it — recursive walker for resolving a text block by key inside containers; pairs with getEnclosingTextBlockKey for fragment-side path walking.

Testing

  • pnpm check:types
  • pnpm check:format
  • pnpm exec eslint packages/sanity/src/core/form/inputs/PortableText/ packages/sanity/src/core/comments/utils/inline-comments/
  • pnpm --filter sanity exec vitest run src/core/comments/__tests__/buildRangeDecorationSelectionsFromComments ✅ (6 passed, 3 pre-existing skipped)

Notes for release

N/A — internal rewire that enables container plugin composition. Aligns Studio with the PTE v7 render pipeline introduced in @portabletext/editor@7.2.0.

bjoerge and others added 8 commits June 4, 2026 15:08
Brings in the `'*'` catch-all node registration sentinel
(`defineX({type: '*'})`) added in `@portabletext/editor@7.2.0`,
required by the Compositor rewire.

Cascade-bumps the editor plugins to their matching .9 patches.
…erers

`@portabletext/editor@7.2.0` introduces a `'*'` catch-all sentinel
for the `defineX` node registration factories. Wiring three such
catch-alls through `<NodePlugin>` inside Compositor lets container
plugins compose with Studio's existing block/inline-object chrome,
list-item rendering, and style wrapping — without expanding Studio's
public API surface.

- `defineTextBlock({type: '*'})` — text blocks of any `_type`. The
  catch-all wraps editable children in Studio's `<Style>` and
  `<ListItem>` components since under `defineTextBlock` the engine
  no longer applies its default style/list-item wrapping.
- `defineBlockObject({type: '*'})` — non-text blocks. Falls through
  to the engine default when the type isn't enumerated by the
  Sanity form-store walker (e.g. types declared inside a container's
  `of` array).
- `defineInlineObject({type: '*'})` — inline objects. Same
  fall-through behaviour for container-nested types.

Annotations remain on the legacy `renderAnnotation` callback;
the PTE engine fires it regardless of the new pipeline.
`usePortableTextMemberItemsFromProps` previously enumerated form
member items at a fixed depth — text blocks at the array's top
level, plus `children` (inline objects) and `markDefs` (annotations)
inside each text block. Container API v2 lets a block-object declare
an `arrayField` (`list.items`, `list-item.content`, …) that contains
more Portable Text nodes; objects living inside those nested arrays
were not enumerated, so clicking an image inside a list item never
opened its edit dialog.

Extract the per-block branch as a recursive `collectFromBlockItem`
that walks every array-of-objects field a block-object declares,
collecting nested block-objects, text blocks, inline objects, and
annotations at any depth.
`buildRangeDecorationSelectionsFromComments` and
`buildTextSelectionFromFragment` previously located a comment's
target text block via root-level `value.find(b => b._key === ...)`.
With Container API v2 a text block may live inside a container
(e.g. `list.items[].content[]`); the root-level find misses it
and comments appear unlinked from their target text.

Extract a shared `findTextBlockByKey` walker that descends into
every array-valued field on each item, returning the block plus
the full keyed path from the root for use as a `RangeDecoration`
selection path.

Pair it with `getEnclosingTextBlockKey` for the fragment helper,
which used to read `path[0]._key` and now walks the path finding
the keyed segment immediately before the `'children'` string
segment.
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
auth-test-studio Ready Ready Preview, Comment Jun 5, 2026 10:20am
page-building-studio Ready Ready Preview, Comment Jun 5, 2026 10:20am
test-studio Ready Ready Preview, Comment Jun 5, 2026 10:20am

Request Review

@socket-security

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

❌ E2E Tests

🟢 199 passed🔴 2 failed🟡 5 flaky • (⚪ 90 skipped) • view full reportview run

Debug failing tests locally
SANITY_E2E_PROJECT_ID=ittbm412 \
SANITY_E2E_BASE_URL=https://e2e-studio-5sao25ciu.sanity.dev \
SANITY_E2E_DATASET=pr-12963-chromium-27009344885 \
SANITY_E2E_DATASET_CHROMIUM=pr-12963-chromium-27009344885 \
SANITY_E2E_DATASET_FIREFOX=pr-12963-firefox-27009344885 \
pnpm test:e2e --headed \
  e2e/tests/pte/referencesInPopover.spec.ts

Studio: https://e2e-studio-5sao25ciu.sanity.dev

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — sanity

Compared against next-major (3bb48ed0) · v5.30.0 (npm)

sanity

Metric Value vs next-major (3bb48ed) vs v5.30.0
Internal (raw) 4.55 MB +1.8 KB, +0.0% +4.2 KB, +0.1%
Internal (gzip) 1.05 MB +792 B, +0.1% +1.4 KB, +0.1%
Bundled (raw) 12.28 MB +16.6 KB, +0.1% -47.7 KB, -0.4%
Bundled (gzip) 2.76 MB +2.1 KB, +0.1% -11.0 KB, -0.4%
Import time 1.55s -8ms, -0.5% +60ms, +4.0%

bin:sanity

Metric Value vs next-major (3bb48ed) vs v5.30.0
Internal (raw) 7.1 KB - -
Internal (gzip) 2.9 KB - -
Bundled (raw) 7.1 KB - -
Bundled (gzip) 2.8 KB - -
Import time 5ms -0ms, -0.4% +0ms, +6.2%

🗺️ View treemap · 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.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

📚 TypeDoc Generation Result

TypeDoc generated successfully!

  • File size: 8.2M
  • Total exports: 1067
  • Artifact: sanity-typedoc-f00aa1d33010dffe8dcb6be7a01062adf7882936

The TypeDoc JSON file has been generated and validated. All documentation scripts completed successfully.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

⚡️ Editor Performance Report

Updated Fri, 05 Jun 2026 10:26:27 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
arrayI18n (simple-en) 62.5 efps (16ms) 71.4 efps (14ms) -2ms (-12.5%)
article (title) 37.0 efps (27ms) 43.5 efps (23ms) -4ms (-14.8%)
article (body) 50.5 efps (20ms) 56.0 efps (18ms) -2ms (-9.8%)
article (string inside object) 52.6 efps (19ms) 52.6 efps (19ms) +0ms (-/-%)
article (string inside array) 52.6 efps (19ms) 50.0 efps (20ms) +1ms (+5.3%)
recipe (name) 99.9+ efps (10ms) 99.9+ efps (9ms) -1ms (-/-%)
recipe (description) 52.6 efps (19ms) 48.8 efps (21ms) +2ms (+7.9%)
recipe (instructions) 99.9+ efps (5ms) 99.9+ efps (5ms) +0ms (-/-%)
singleString (stringField) 99.9+ efps (7ms) 99.9+ efps (7ms) +1ms (-/-%)
synthetic (title) 55.6 efps (18ms) 52.6 efps (19ms) +1ms (+5.6%)
synthetic (string inside object) 55.6 efps (18ms) 58.8 efps (17ms) -1ms (-5.6%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
arrayI18n (simple-en) 16ms 18ms 21ms 68ms 6ms 6.2s
article (title) 27ms 31ms 51ms 77ms 71ms 8.3s
article (body) 20ms 25ms 36ms 100ms 229ms 5.4s
article (string inside object) 19ms 22ms 28ms 61ms 19ms 6.3s
article (string inside array) 19ms 21ms 24ms 52ms 8ms 6.7s
recipe (name) 10ms 12ms 14ms 33ms 0ms 5.4s
recipe (description) 19ms 22ms 25ms 45ms 0ms 4.4s
recipe (instructions) 5ms 8ms 9ms 15ms 0ms 3.0s
singleString (stringField) 7ms 9ms 12ms 24ms 0ms 4.6s
synthetic (title) 18ms 21ms 28ms 108ms 1350ms 9.7s
synthetic (string inside object) 18ms 20ms 22ms 86ms 1164ms 8.9s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
arrayI18n (simple-en) 14ms 18ms 23ms 66ms 14ms 6.0s
article (title) 23ms 28ms 38ms 58ms 22ms 7.3s
article (body) 18ms 23ms 46ms 79ms 223ms 5.1s
article (string inside object) 19ms 24ms 31ms 66ms 8ms 6.3s
article (string inside array) 20ms 23ms 27ms 54ms 40ms 6.6s
recipe (name) 9ms 11ms 13ms 31ms 0ms 5.3s
recipe (description) 21ms 24ms 30ms 55ms 0ms 4.6s
recipe (instructions) 5ms 8ms 9ms 13ms 0ms 2.9s
singleString (stringField) 7ms 9ms 13ms 32ms 0ms 4.7s
synthetic (title) 19ms 21ms 50ms 92ms 1373ms 9.7s
synthetic (string inside object) 17ms 19ms 42ms 88ms 1357ms 9.1s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 43.07% 29527 / 68541
🔵 Statements 35.74% 39680 / 111013
🔵 Functions 33.01% 6268 / 18986
🔵 Branches 26.71% 23788 / 89035
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/sanity/src/core/comments/utils/inline-comments/buildRangeDecorationSelectionsFromComments.ts 87.35% 68.42% 88.88% 90.24% 76, 85, 108, 112, 117, 170, 180-185
packages/sanity/src/core/comments/utils/inline-comments/buildTextSelectionFromFragment.ts 0% 0% 0% 0% 21-82
packages/sanity/src/core/comments/utils/inline-comments/findTextBlockByKey.ts 31.03% 25% 50% 40.9% 32, 35, 40-48, 62-76
packages/sanity/src/core/form/inputs/PortableText/Compositor.tsx 0% 0% 0% 0% 86-648
packages/sanity/src/core/form/inputs/PortableText/Editor.tsx 3.29% 0% 0% 5.66% 35-209
packages/sanity/src/core/form/inputs/PortableText/hooks/usePortableTextMembers.tsx 0% 0% 0% 0% 17-30
Generated in workflow #56920 for commit 53a1acb by the Vitest Coverage Report Action

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.

3 participants