Skip to content

refactor: collapse mirror duplications#2569

Draft
christianhg wants to merge 5 commits into
mainfrom
refactor/collapse-mirror-duplications
Draft

refactor: collapse mirror duplications#2569
christianhg wants to merge 5 commits into
mainfrom
refactor/collapse-mirror-duplications

Conversation

@christianhg
Copy link
Copy Markdown
Member

A handful of internal helpers had grown up as parallel implementations that differed only by direction (start/end, forward/backward, before/after) or by the property they read (style/listItem). The bodies were near-identical and the duplication made each future audit (depth, container-awareness, path shape) twice the work.

Collapsing them is purely internal. No public selector, operation, or type signature changes; getBlockTextBefore, getBlockTextAfter, getActiveStyle, getActiveListItem, moveForwardOperationImplementation, and moveBackwardOperationImplementation keep their names and external shape. The shared work moves into private helpers (getBlockTextAroundPoint, getActiveBlockProperty, getEdgeBlockElement, removeNodesBetween, isEqualKeyedObjects).

Bundle impact is below gzip resolution (188.4 KB before and after). The win is that there's now one place to fix when a primitive evolves.

Commits

  • refactor: collapse mirror helpers in internal-utilsremoveChildrenBetweenremoveBlocksBetween and isEqualInlineObjectsisEqualPortableTextObjects had byte-identical bodies. Each pair becomes one helper.
  • refactor: merge move.forward and move.backward operations — both files differed only by a reverse: true flag. One file with two named exports.
  • refactor: collapse start/end block-element helpers in editor-domgetStartBlockElement and getEndBlockElement reduced to a single getEdgeBlockElement(slateEditor, snapshot, edge) called inline by the EditorDom factory.
  • refactor: share helper between getBlockTextBefore and getBlockTextAfter — both selectors now forward to a private getBlockTextAroundPoint(snapshot, point, edge).
  • refactor: share helper between getActiveStyle and getActiveListItem — both selectors now forward to getActiveBlockProperty(snapshot, key).

No changesets — none of these changes are consumer-visible.

`removeChildrenBetween` and `removeBlocksBetween` had byte-identical
bodies. Both walked siblings forward via `getSibling` until reaching the
end path; the block-vs-child distinction was purely cosmetic and the
walker is depth-agnostic. Collapsed to one `removeNodesBetween`.

`isEqualInlineObjects` and `isEqualPortableTextObjects` had byte-identical
bodies (key/type short-circuit, then `isEqualProps` excluding `_key` and
`_type`). Collapsed to one `isEqualKeyedObjects`. Both call sites reach
the same implementation now.
Both files differed only by a `reverse: true` flag passed to `applyMove`.
Collapsed into one `operation.move.ts` exporting both
`moveForwardOperationImplementation` and `moveBackwardOperationImplementation`,
each a four-line wrapper around `applyMove`. The dispatcher in
`operation.perform.ts` keeps the same two named imports, just from one
file.
`getStartBlockElement` and `getEndBlockElement` had identical bodies
except for the selector they called and the `instanceof Element` return
phrasing. Replaced with one `getEdgeBlockElement(slateEditor, snapshot,
edge)` that picks the start or end selection block based on the edge
arg. The two outer factories on `EditorDom` keep their names and call
the unified helper inline.
Both selectors had the same shape: pick a selection point, find the
focus text block at that point, compute the block's matching edge, and
return text between the point and the edge. Extracted the shared work
into a private `getBlockTextAroundPoint(snapshot, point, edge)` helper.
The two public selectors stay as named exports.
Both selectors had the same shape: gather selected text blocks, return
the value of a given block-level property if every block agrees on it,
otherwise `undefined`. Extracted to a private
`getActiveBlockProperty(snapshot, key)` helper keyed on the property
name. The public `getActiveStyle` and `getActiveListItem` selectors
stay as named exports and forward to the helper.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 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 30, 2026 1:29pm
portable-text-example-basic Ready Ready Preview, Comment Apr 30, 2026 1:29pm
portable-text-playground Ready Ready Preview, Comment Apr 30, 2026 1:29pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

⚠️ No Changeset found

Latest commit: 4ac9090

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

📦 Bundle Stats — @portabletext/editor

Compared against main (7a1fc738)

@portabletext/editor

Metric Value vs main (7a1fc73)
Internal (raw) 724.2 KB -1.2 KB, -0.2%
Internal (gzip) 138.6 KB -58 B, -0.0%
Bundled (raw) 1.32 MB -1.2 KB, -0.1%
Bundled (gzip) 298.8 KB -62 B, -0.0%
Import time 95ms +1ms, +1.6%

@portabletext/editor/behaviors

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

@portabletext/editor/plugins

Metric Value vs main (7a1fc73)
Internal (raw) 3.1 KB -
Internal (gzip) 967 B -
Bundled (raw) 2.9 KB -
Bundled (gzip) 899 B -
Import time 8ms +0ms, +0.0%

@portabletext/editor/selectors

Metric Value vs main (7a1fc73)
Internal (raw) 76.1 KB -469 B, -0.6%
Internal (gzip) 13.7 KB +31 B, +0.2%
Bundled (raw) 71.4 KB -469 B, -0.6%
Bundled (gzip) 12.6 KB +19 B, +0.1%
Import time 7ms -0ms, -0.2%

@portabletext/editor/utils

Metric Value vs main (7a1fc73)
Internal (raw) 27.8 KB -
Internal (gzip) 5.5 KB -
Bundled (raw) 25.4 KB -
Bundled (gzip) 5.1 KB -
Import time 6ms -0ms, -0.0%

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

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