refactor: collapse mirror duplications#2569
Draft
christianhg wants to merge 5 commits into
Draft
Conversation
`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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Contributor
📦 Bundle Stats —
|
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andmoveBackwardOperationImplementationkeep 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-utils—removeChildrenBetween≡removeBlocksBetweenandisEqualInlineObjects≡isEqualPortableTextObjectshad byte-identical bodies. Each pair becomes one helper.refactor: merge move.forward and move.backward operations— both files differed only by areverse: trueflag. One file with two named exports.refactor: collapse start/end block-element helpers in editor-dom—getStartBlockElementandgetEndBlockElementreduced to a singlegetEdgeBlockElement(slateEditor, snapshot, edge)called inline by theEditorDomfactory.refactor: share helper between getBlockTextBefore and getBlockTextAfter— both selectors now forward to a privategetBlockTextAroundPoint(snapshot, point, edge).refactor: share helper between getActiveStyle and getActiveListItem— both selectors now forward togetActiveBlockProperty(snapshot, key).No changesets — none of these changes are consumer-visible.