Skip to content

refactor: collapse editor publication onto a single publisher#2767

Draft
christianhg wants to merge 1 commit into
mainfrom
feat/publisher
Draft

refactor: collapse editor publication onto a single publisher#2767
christianhg wants to merge 1 commit into
mainfrom
feat/publisher

Conversation

@christianhg

@christianhg christianhg commented Jun 9, 2026

Copy link
Copy Markdown
Member

The editor's publication surface — the channel backing editor.on — was split across three layers: a relay xstate machine that owned selection-dedup and re-emitted everything, actor bridges in create-editor.ts that forwarded editor-actor / mutation-actor / sync-actor events into the relay, and the Editable component reaching for a RelayActorContext to dispatch lifecycle events directly. One relayActor.on('*') bridge then translated every event back into a listener(event) call inside create-editor.

Replace the relay with a single Publisher. The publisher owns the selection-dedup + focus-flag carve-out (ported verbatim from the relay machine) and is the only thing editor.on reads from. The bridges that used to forward into the relay now call publisher.emit directly. Editable reaches the publisher through the engine and emits focused, blurred, loading, done loading without touching the actor system.

The relay machine, its React context, and the actors.relayActor handle are gone. The deprecated 'unset' event (never re-emitted to consumers anyway) goes with them.

// internal seam, not exported
export type Publisher = {
  emit: (event: EditorEmittedEvent) => void
  on: <TType extends EditorEmittedEvent['type'] | '*'>(
    type: TType,
    listener: (
      event: EditorEmittedEvent & (TType extends '*' ? unknown : {type: TType}),
    ) => void,
  ) => Subscription
}

Public behavior

Unchanged. editor.on(eventType, listener) accepts the same event union, returns the same Subscription shape, and dedupes selection events with the same focus-flag carve-out the relay machine implemented.

Verification

  • Publisher unit tests cover the typed channel, the wildcard, unsubscribe, and the five selection-dedup edges
  • editor.on consumer tests pass on chromium: tests/event.select, tests/focus, tests/behavior-api, tests/event.insert.inline-object, tests/setup, tests/validation, tests/insert-block, tests/self-solving
  • Workspace types + lint + format + unit (759/759) clean

No changeset

Pure-internal refactor, no consumer-observable delta.

@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3071532

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

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 Jun 9, 2026 5:41pm
portable-text-example-basic Ready Ready Preview, Comment Jun 9, 2026 5:41pm
portable-text-playground Ready Ready Preview, Comment Jun 9, 2026 5:41pm

Request Review

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @portabletext/editor

Compared against main (df697572)

@portabletext/editor

Metric Value vs main (df69757)
Internal (raw) 776.5 KB -1.2 KB, -0.1%
Internal (gzip) 147.7 KB -123 B, -0.1%
Bundled (raw) 1.38 MB -1.1 KB, -0.1%
Bundled (gzip) 309.6 KB -115 B, -0.0%
Import time 97ms -0ms, -0.4%

@portabletext/editor/behaviors

Metric Value vs main (df69757)
Internal (raw) 467 B -
Internal (gzip) 207 B -
Bundled (raw) 424 B -
Bundled (gzip) 171 B -
Import time 2ms -0ms, -1.0%

@portabletext/editor/plugins

Metric Value vs main (df69757)
Internal (raw) 2.7 KB -
Internal (gzip) 894 B -
Bundled (raw) 2.5 KB -
Bundled (gzip) 827 B -
Import time 7ms +0ms, +0.2%

@portabletext/editor/selectors

Metric Value vs main (df69757)
Internal (raw) 79.3 KB -
Internal (gzip) 14.5 KB -
Bundled (raw) 74.8 KB -
Bundled (gzip) 13.4 KB -
Import time 8ms -0ms, -0.3%

@portabletext/editor/traversal

Metric Value vs main (df69757)
Internal (raw) 25.4 KB -
Internal (gzip) 5.0 KB -
Bundled (raw) 25.4 KB -
Bundled (gzip) 5.0 KB -
Import time 6ms -0ms, -0.1%

@portabletext/editor/utils

Metric Value vs main (df69757)
Internal (raw) 28.7 KB -
Internal (gzip) 6.0 KB -
Bundled (raw) 26.7 KB -
Bundled (gzip) 5.7 KB -
Import time 6ms -0ms, -1.6%

🗺️ . · ./behaviors · ./plugins · ./selectors · ./traversal · ./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.

📦 Bundle Stats — @portabletext/markdown

Compared against main (df697572)

Metric Value vs main (df69757)
Internal (raw) 53.0 KB -
Internal (gzip) 9.6 KB -
Bundled (raw) 347.6 KB -
Bundled (gzip) 96.0 KB -
Import time 39ms +1ms, +3.1%

🗺️ 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.

The editor's publication surface — the channel backing `editor.on` — was
split across the relay xstate machine, the actor bridges in
`create-editor`, and the `Editable` component reaching for a
`RelayActorContext` to dispatch lifecycle events directly. Three sources
fed `relayActor.send`; one `relayActor.on('*')` bridge then translated
every event back into a `listener(event)` call inside `create-editor`.

Replace it with a single `Publisher`. The publisher owns the
selection-dedup + focus-flag carve-out (ported verbatim from the relay
machine) and is the only thing `editor.on` reads from. The bridges that
used to forward editor-actor, mutation-actor and sync-actor emissions
into the relay now call `publisher.emit` directly. `Editable` reaches
the publisher through the engine and emits `focused`, `blurred`,
`loading`, `done loading` without touching the actor system.

The relay machine, its React context, and the `actors.relayActor`
handle are gone. The deprecated `'unset'` event (never re-emitted to
consumers anyway) goes with them.

Public behavior is unchanged. The `EditorEmittedEvent` union is the same.
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