feat: Portable Text-native node traversal#2398
Draft
christianhg wants to merge 17 commits intomainfrom
Draft
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (055bdb1) |
|---|---|---|
| Internal (raw) | 771.7 KB | +16.7 KB, +2.2% |
| Internal (gzip) | 144.1 KB | +2.2 KB, +1.5% |
| Bundled (raw) | 1.38 MB | +16.7 KB, +1.2% |
| Bundled (gzip) | 306.9 KB | +2.1 KB, +0.7% |
| Import time | 106ms | -0ms, -0.4% |
@portabletext/editor/behaviors
| Metric | Value | vs main (055bdb1) |
|---|---|---|
| Internal (raw) | 467 B | - |
| Internal (gzip) | 207 B | - |
| Bundled (raw) | 424 B | - |
| Bundled (gzip) | 171 B | - |
| Import time | 6ms | -0ms, -4.8% |
@portabletext/editor/plugins
| Metric | Value | vs main (055bdb1) |
|---|---|---|
| Internal (raw) | 2.5 KB | - |
| Internal (gzip) | 910 B | - |
| Bundled (raw) | 2.3 KB | - |
| Bundled (gzip) | 839 B | - |
| Import time | 12ms | -1ms, -5.9% |
@portabletext/editor/selectors
| Metric | Value | vs main (055bdb1) |
|---|---|---|
| Internal (raw) | 60.2 KB | - |
| Internal (gzip) | 9.4 KB | - |
| Bundled (raw) | 56.7 KB | - |
| Bundled (gzip) | 8.6 KB | - |
| Import time | 11ms | -0ms, -2.2% |
@portabletext/editor/utils
| Metric | Value | vs main (055bdb1) |
|---|---|---|
| Internal (raw) | 24.2 KB | - |
| Internal (gzip) | 4.7 KB | - |
| Bundled (raw) | 22.2 KB | - |
| Bundled (gzip) | 4.4 KB | - |
| Import time | 10ms | -0ms, -2.3% |
🗺️ . · ./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.
e1709db to
54eedf1
Compare
54eedf1 to
cfdcf10
Compare
a16d425 to
285fe40
Compare
cfdcf10 to
d648f4d
Compare
88a9829 to
d8e304e
Compare
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.
The vendored Slate layer inherited a node traversal system that hardcodes
.childrenas the only field that can contain child nodes. This works for flat content and even nested structures, but not for containers where children live in schema-defined fields likerows,cells, orcontent. This PR replaces that system withsrc/node-traversal/, a set of functions that use the schema to resolve children on any node type.The new traversal handles three cases uniformly: editor root nodes and text blocks (use
.children), container objects (look up the schema-defined child field viaresolveChildArrayField), and everything else (leaf nodes, no children). All seven functions share a consistent signature taking a context object with schema and editable types, a root node, and an indexed path:getChildren,getNode,getNodes,getFirst,getLast,getParent,hasNode.Container traversal is gated by
editableTypes, aSet<string>on the editor that lists which object types have editable content (e.g.'table','table.row','table.row.cell'). When traversal encounters an object node, it checkseditableTypesbefore descending into its child field. This set is currently always empty, meaning containers are traversed as leaf nodes today. A future PR will populate it based on registered renderers, enabling container editing without changing the traversal layer.The old
slate/node/helpers (getChild,getChildren,getFirst,getLast,getLeaf,getLevels,getNodeIf,getNode,getNodes,getSpanNode,getString,getTextBlockNode,getTexts,hasNode,isLeaf) andslate/editor/wrappers (node,leaf,hasPath,getObjectNode) are inlined at their call sites and deleted. The higher-level functionsabove,nodes, andlevelsremain since they add location resolution and match filtering that callers depend on, but they now delegate to the new traversal internally.Note
All traversal functions return
undefinedon failure instead of throwing. This is a deliberate shift from Slate's original philosophy of throwing on every invalid path. The editor runs in a racy DOM environment where transient path mismatches are normal during React re-renders, not bugs that should crash the component tree.