Skip to content

Handle numbers and booleans in slate-hyperscript - #6102

Open
12joan wants to merge 2 commits into
ianstormtaylor:mainfrom
12joan:ft/jsx-numbers-and-booleans
Open

Handle numbers and booleans in slate-hyperscript#6102
12joan wants to merge 2 commits into
ianstormtaylor:mainfrom
12joan:ft/jsx-numbers-and-booleans

Conversation

@12joan

@12joan 12joan commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Description
Previously, trying to include a number or boolean as a child in slate-hyperscript resulted in an error like Error: Unexpected hyperscript child object: <value>.

This PR updates the child handling logic to make number and boolean handling consistent with React JSX. Numbers are converted to strings, and booleans are ignored.

Example

<element>{4}</element> // Element containing { text: '4' }
<element>{true}{false}</element> // Empty element, since true and false are ignored

Context
Since JSX is not type-safe, it's quite common to accidentally pass a number instead of a string as a child of a JSX tag when creating JSX dynamically.

Ignoring booleans lets us safely use patterns like {condition && <element />}.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e474d91

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

This PR includes changesets to release 1 package
Name Type
slate-hyperscript 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

return !!match
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From yarn fix

name: 'Autocorrect',
instructions:
'Type "Cant", then press space to autocorrect it. Make sure the cursor position is correct (after the autocorrected word)',
'Type "Cant" (make sure to misspell it), then press space to autocorrect it. Make sure the cursor position is correct (after the autocorrected word)',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From yarn fix

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