Skip to content

Conversation

@christianhg
Copy link
Member

Previously, every Behavior Event required filtering all registered behaviors to find matches.

Now, we have a Behavior Index that pre-categorizes Behaviors by their on pattern:

  • global: Behaviors with on: '*'
  • namespaced: Behaviors with patterns like on: 'select.*'
  • exact: Behaviors with patterns like on: 'insert.text'

Performing a Behavior Event now does O(1) map lookups instead of filtering, then merges and sorts the results to preserve priority order. The merging and sorting still allocates and iterates arrays, albeit a lot smaller.

In the case of Behavior addition and removal, the index is marked as stale and then it is lazily rebuilt when the next Behavior Event is triggered. This mimics the previous caching Behavior sort order.

Previously, every Behavior Event required filtering all registered behaviors
to find matches.

Now, we have a Behavior Index that pre-categorizes Behaviors by their `on`
pattern:

- `global`: Behaviors with `on: '*'`
- `namespaced`: Behaviors with patterns like `on: 'select.*'`
- `exact`: Behaviors with patterns like `on: 'insert.text'`

Performing a Behavior Event now does O(1) map lookups instead of filtering,
then merges and sorts the results to preserve priority order. The merging and
sorting still allocates and iterates arrays, albeit a lot smaller.

In the case of Behavior addition and removal, the index is marked as stale and
then it is lazily rebuilt when the next Behavior Event is triggered. This
mimics the previous caching Behavior sort order.
@changeset-bot
Copy link

changeset-bot bot commented Dec 22, 2025

🦋 Changeset detected

Latest commit: ca1c313

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

This PR includes changesets to release 9 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-sdk-value 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

@vercel
Copy link

vercel bot commented Dec 22, 2025

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

Project Deployment Review Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment Dec 22, 2025 9:22am
portable-text-example-basic Ready Ready Preview, Comment Dec 22, 2025 9:22am
portable-text-example-legacy Ready Ready Preview, Comment Dec 22, 2025 9:22am
portable-text-playground Ready Ready Preview, Comment Dec 22, 2025 9:22am

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.

2 participants