refactor: replace blockIndexMap with json-match getIndexForKey#2347
Closed
christianhg wants to merge 1 commit intomainfrom
Closed
refactor: replace blockIndexMap with json-match getIndexForKey#2347christianhg wants to merge 1 commit intomainfrom
christianhg wants to merge 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (d312abd) |
|---|---|---|
| Internal (raw) | 799.9 KB | -1.1 KB, -0.1% |
| Internal (gzip) | 150.3 KB | -1 B, -0.0% |
| Bundled (raw) | 1.41 MB | -883 B, -0.1% |
| Bundled (gzip) | 313.3 KB | +71 B, +0.0% |
| Import time | 91ms | +0ms, +0.1% |
@portabletext/editor/behaviors
| Metric | Value | vs main (d312abd) |
|---|---|---|
| Internal (raw) | 467 B | - |
| Internal (gzip) | 207 B | - |
| Bundled (raw) | 424 B | - |
| Bundled (gzip) | 171 B | - |
| Import time | 6ms | +0ms, +0.5% |
@portabletext/editor/plugins
| Metric | Value | vs main (d312abd) |
|---|---|---|
| Internal (raw) | 2.5 KB | - |
| Internal (gzip) | 910 B | - |
| Bundled (raw) | 2.3 KB | - |
| Bundled (gzip) | 839 B | - |
| Import time | 11ms | +0ms, +0.2% |
@portabletext/editor/selectors
| Metric | Value | vs main (d312abd) |
|---|---|---|
| Internal (raw) | 60.2 KB | +46 B, +0.1% |
| Internal (gzip) | 9.4 KB | +20 B, +0.2% |
| Bundled (raw) | 57.0 KB | +321 B, +0.6% |
| Bundled (gzip) | 8.8 KB | +142 B, +1.6% |
| Import time | 11ms | +1ms, +10.6% |
@portabletext/editor/utils
| Metric | Value | vs main (d312abd) |
|---|---|---|
| Internal (raw) | 24.2 KB | - |
| Internal (gzip) | 4.7 KB | - |
| Bundled (raw) | 22.2 KB | - |
| Bundled (gzip) | 4.4 KB | - |
| Import time | 9ms | +0ms, +0.2% |
Details
- Import time regressions over 10% are flagged with
⚠️ - Treemap artifacts are attached to the CI run for detailed size analysis
- 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.
Replaces all
blockIndexMaplookups withgetIndexForKeyfrom@sanity/json-match. This is the first step toward usingjson-matchas the tree traversal and path engine for the editor, which is needed for container support.getIndexForKeydoes the same thing asblockIndexMap.get(key)— finds the array index of an item by its_key— but uses aWeakMapcache keyed by array reference instead of a manually maintainedMap. Since Slate produces a newchildrenarray on every operation, the cache is effectively rebuilt on first access after each change, same asblockIndexMap. The advantage is that it requires no explicit rebuild step and comes from a library that also provides the path expression engine we need for containers.What changed
Every
blockIndexMap.get(key)call becomesgetIndexForKey(value, key). EveryblockIndexMap.has(key)call becomesgetIndexForKey(value, key) !== undefined. TheblockIndexMapproperty was removed fromEditorSnapshotsince nothing reads it anymore. The property still exists onPortableTextSlateEditorandbuildIndexMapsstill runs — removing those is a separate step.toSlateRangeandtoSlateSelectionPointno longer takeblockIndexMapin their parameter types. They callgetIndexForKeydirectly on the value array. This simplified all call sites that were previously constructing snapshot objects just to pass the map through.36 files changed, +84/-77 lines.
How it was tested
Type check, lint, 244 unit tests, 740 browser tests (chromium). All pass.