Skip to content

Comments

Smart set_node: relax text/children constraints for void elements#2224

Draft
christianhg wants to merge 1 commit intomainfrom
feat/smart-set-node
Draft

Smart set_node: relax text/children constraints for void elements#2224
christianhg wants to merge 1 commit intomainfrom
feat/smart-set-node

Conversation

@christianhg
Copy link
Member

Relaxes the set_node operation constraints so that text and children properties are only rejected when they would violate Slate's data model — not unconditionally.

What changed

general.ts (operation handler):

  • text: Only throws for Text nodes (must use insert_text/remove_text for history correctness)
  • children: Only throws for non-void Elements (structural children must not be set directly)

set-nodes.ts (Transforms.setNodes):

  • Same conditional filtering — text skipped for Text nodes, children skipped for non-void Elements

apply-operation-to-portable-text.ts (PT value layer):

  • Skips children when applying set_node to object nodes, preventing Slate void-child internals from leaking into portable text output

Why

Opens a path for PR 3 (childless voids + value unification) to set properties on void elements via set_node operations. No behavior change for non-void nodes — existing tests pass unchanged.

Base branch

Based on feat-vendor-slate (PR #2188).

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

🦋 Changeset detected

Latest commit: f05452c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@portabletext/editor Patch
@portabletext/plugin-character-pair-decorator Patch
@portabletext/plugin-emoji-picker Patch
@portabletext/plugin-input-rule Patch
@portabletext/plugin-markdown-shortcuts Patch
@portabletext/plugin-one-line Patch
@portabletext/plugin-paste-link Patch
@portabletext/plugin-sdk-value Patch
@portabletext/plugin-typeahead-picker Patch
@portabletext/plugin-typography Patch
@portabletext/toolbar Patch

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

@vercel
Copy link

vercel bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment Feb 23, 2026 11:38am
portable-text-example-basic Ready Ready Preview, Comment Feb 23, 2026 11:38am
portable-text-playground Ready Ready Preview, Comment Feb 23, 2026 11:38am

Request Review

christianhg added a commit that referenced this pull request Feb 20, 2026
The childless voids commit (e1d2c4c) reverted the smart set_node
guards from PR #2224 back to unconditional text/children rejection.

Restores context-aware guards in both locations:
- general.ts (operation handler): only throw for 'text' on Text nodes,
  only throw for 'children' on non-void Elements
- set-nodes.ts (Transforms.setNodes): same conditional filtering

Uses instance methods (editor.isText, editor.isElement, editor.isVoid)
consistent with the Phase 2 migration.

Also fixes prettier formatting on 8 files flagged by CI.
Base automatically changed from feat-vendor-slate to main February 23, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant