fix: validate getSibling's blockIndexMap index against the value#2878
Draft
christianhg wants to merge 1 commit into
Draft
fix: validate getSibling's blockIndexMap index against the value#2878christianhg wants to merge 1 commit into
getSibling's blockIndexMap index against the value#2878christianhg wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 5a5950f The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (24996df) |
|---|---|---|
| Internal (raw) | 792.6 KB | +327 B, +0.0% |
| Internal (gzip) | 151.5 KB | +63 B, +0.0% |
| Bundled (raw) | 1.40 MB | +331 B, +0.0% |
| Bundled (gzip) | 315.6 KB | +75 B, +0.0% |
| Import time | 95ms | -1ms, -1.0% |
@portabletext/editor/behaviors
| Metric | Value | vs main (24996df) |
|---|---|---|
| Internal (raw) | 467 B | - |
| Internal (gzip) | 207 B | - |
| Bundled (raw) | 424 B | - |
| Bundled (gzip) | 171 B | - |
| Import time | 2ms | -0ms, -0.7% |
@portabletext/editor/plugins
| Metric | Value | vs main (24996df) |
|---|---|---|
| Internal (raw) | 2.7 KB | - |
| Internal (gzip) | 894 B | - |
| Bundled (raw) | 2.5 KB | - |
| Bundled (gzip) | 827 B | - |
| Import time | 7ms | -0ms, -1.4% |
@portabletext/editor/selectors
| Metric | Value | vs main (24996df) |
|---|---|---|
| Internal (raw) | 79.7 KB | +327 B, +0.4% |
| Internal (gzip) | 14.6 KB | +62 B, +0.4% |
| Bundled (raw) | 75.2 KB | +327 B, +0.4% |
| Bundled (gzip) | 13.5 KB | +73 B, +0.5% |
| Import time | 8ms | -0ms, -0.9% |
@portabletext/editor/traversal
| Metric | Value | vs main (24996df) |
|---|---|---|
| Internal (raw) | 25.6 KB | +327 B, +1.3% |
| Internal (gzip) | 5.1 KB | +63 B, +1.2% |
| Bundled (raw) | 25.5 KB | +327 B, +1.3% |
| Bundled (gzip) | 5.0 KB | +65 B, +1.3% |
| Import time | 6ms | +0ms, +3.0% |
@portabletext/editor/utils
| Metric | Value | vs main (24996df) |
|---|---|---|
| Internal (raw) | 29.4 KB | - |
| Internal (gzip) | 6.2 KB | - |
| Bundled (raw) | 27.0 KB | - |
| Bundled (gzip) | 5.8 KB | - |
| Import time | 6ms | +0ms, +0.3% |
🗺️ . · ./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 (24996df6)
| Metric | Value | vs main (24996df) |
|---|---|---|
| Internal (raw) | 53.0 KB | - |
| Internal (gzip) | 9.6 KB | - |
| Bundled (raw) | 348.2 KB | - |
| Bundled (gzip) | 96.1 KB | - |
| Import time | 40ms | -0ms, -0.7% |
🗺️ 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.
`getSibling` looked up the current node's index with `blockIndexMap.get(serializePath(path))` and trusted it blindly, then indexed the value-derived sibling array (from `getChildren`) with it. `blockIndexMap` can miss (an unkeyed transient node) or disagree with the traversed value (a snapshot that pairs the live map with a pre-apply value, e.g. `textPatch`). On a miss the lookup returned `undefined`, so `getSibling` reported no sibling where one exists; on a disagreement the stale index pointed at the wrong slot in the value-derived array, returning the wrong sibling. `getNode`, `getChildren`, and `getAncestors` all take the map as a fast path and fall back to a value scan when it misses or disagrees; `getSibling` was the lone holdout trusting it unconditionally. It now validates the mapped index against the resolved `children` (does the child at that index carry the path's last keyed `_key`?) and scans only when it doesn't. The O(1) lookup is preserved in the common case; the O(n) scan runs only on the stale-map snapshots. `children` itself was already materialized (and O(n)) to return the sibling, so the fast path adds no asymptotic cost. Surfaced by the traversal audit that followed the `getNode` path-contract fix. Net behavior unchanged when the map and value agree.
9ada9b3 to
5a5950f
Compare
getSibling from the value rather than blockIndexMapgetSibling's blockIndexMap index against the value
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.
Found by the traversal audit that followed the
getNodepath-contract fix (#2876, EDEX-1425), same family: a util over-trustingblockIndexMapwithout the value fallback the rest of the traversal layer carries.getSiblinglooked up the current node's index withblockIndexMap.get(serializePath(path))and trusted it blindly, then indexed the value-derived sibling array (fromgetChildren) with it.blockIndexMapcan miss (an unkeyed transient node) or disagree with the traversed value (a snapshot that pairs the live map with a pre-apply value, e.g.textPatch):undefined, sogetSiblingreported no sibling where one exists.getNode,getChildren, andgetAncestorsall take the map as a fast path and fall back to a value scan when it misses or disagrees;getSiblingwas the lone holdout trusting it unconditionally. It now validates the mapped index against the resolvedchildren(does the child at that index carry the path's last keyed_key?) and scans only when it doesn't.The O(1) lookup is preserved in the common case; the O(n) scan runs only on the stale-map snapshots.
childrenwas already materialized bygetChildren(itself O(n)) to return the sibling node + path, so the fast path adds no asymptotic cost over what the function already did.TDD: the new test (
resolves the sibling from the value when the blockIndexMap misses) pairs the testbed value with an empty map and asserts next/previous/nested-span siblings still resolve. It fails onmain(returnsundefined) and passes with the fix; the existing 21 cases are unchanged.Net behavior is unchanged when the map and value agree.
816editor unit tests pass; types, lint, knip green.