fix: use lax type guards for text block and span identification#2421
Merged
christianhg merged 1 commit intomainfrom Mar 27, 2026
Merged
fix: use lax type guards for text block and span identification#2421christianhg merged 1 commit intomainfrom
christianhg merged 1 commit intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 3ffb53e The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 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 (56c20c3) |
|---|---|---|
| Internal (raw) | 760.3 KB | +419 B, +0.1% |
| Internal (gzip) | 143.0 KB | -142 B, -0.1% |
| Bundled (raw) | 1.37 MB | +342 B, +0.0% |
| Bundled (gzip) | 305.8 KB | -104 B, -0.0% |
| Import time | 97ms | +1ms, +1.4% |
@portabletext/editor/behaviors
| Metric | Value | vs main (56c20c3) |
|---|---|---|
| Internal (raw) | 467 B | - |
| Internal (gzip) | 207 B | - |
| Bundled (raw) | 424 B | - |
| Bundled (gzip) | 171 B | - |
| Import time | 6ms | -0ms, -0.8% |
@portabletext/editor/plugins
| Metric | Value | vs main (56c20c3) |
|---|---|---|
| Internal (raw) | 2.5 KB | - |
| Internal (gzip) | 910 B | - |
| Bundled (raw) | 2.3 KB | - |
| Bundled (gzip) | 839 B | - |
| Import time | 12ms | -0ms, -0.1% |
@portabletext/editor/selectors
| Metric | Value | vs main (56c20c3) |
|---|---|---|
| Internal (raw) | 60.5 KB | +322 B, +0.5% |
| Internal (gzip) | 9.5 KB | +71 B, +0.7% |
| Bundled (raw) | 56.9 KB | +262 B, +0.5% |
| Bundled (gzip) | 8.7 KB | +42 B, +0.5% |
| Import time | 10ms | -0ms, -0.8% |
@portabletext/editor/utils
| Metric | Value | vs main (56c20c3) |
|---|---|---|
| Internal (raw) | 24.2 KB | - |
| Internal (gzip) | 4.7 KB | - |
| Bundled (raw) | 22.2 KB | - |
| Bundled (gzip) | 4.4 KB | - |
| Import time | 9ms | -0ms, -1.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.
7d4d2e3 to
3ffb53e
Compare
children property during normalization and rendering
Merged
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.
Adds
isTextBlockNodeand sweeps the codebase to use lax type guards (isTextBlockNode,isSpanNode) where the strict versions (isTextBlock,isSpan) aren't needed.isTextBlockfrom@portabletext/schemarequireschildrento be an array.isSpanrequirestextto be a string. These strict checks are correct when the code accesses.childrenor.texton the narrowed type, but they cause type lies at discriminator sites. For example,isBlockused!isTextBlock(parent)to determine if a node's parent is a text block. If a text block arrives withoutchildren,isTextBlockreturns false, andisBlockincorrectly returns true for its children - spans get misidentified as blocks.isTextBlockNodechecks_typeagainstschema.block.namewithout requiringchildren.isSpanNode(from #2420) checks_typeagainstschema.span.namewithout requiringtext. These are the right guards for code that just needs to know what type a node is.The sweep follows a simple rule: use the lax guard everywhere except where
.childrenor.textis accessed on the narrowed type. 26 files changed across behaviors, selectors, operations, node traversal, Slate core, and rendering.The normalization plugin uses
isTextBlockNodeformarkDefsandstylechecks (which don't needchildren), and keepsisTextBlockfor span merging and orphaned annotation removal (which do). The rendering layer gets fallbacks for text blocks withoutchildrenand spans withouttext- rendernullinstead of throwing.