ianstormtaylor/slate · error · Error

Unexpected hyperscript child object: ${child}

Error message

Unexpected hyperscript child object: ${child}

What it means

Thrown by hyperscript's addChild when a child value passed into an element creator is of an unrecognized type — not a string, number, Slate node, Token, or JSX element the creator knows how to handle.

Source

Thrown at packages/slate-hyperscript/src/creators.ts:69

    } else if (Element.isElement(child)) {
      nodes.push(child)
    } else if (child instanceof Token) {
      let n = nodes[nodes.length - 1]

      if (!Text.isText(n)) {
        addChild('')
        n = nodes[nodes.length - 1] as Text
      }

      if (child instanceof AnchorToken) {
        addAnchorToken(n, child)
      } else if (child instanceof FocusToken) {
        addFocusToken(n, child)
      } else if (child instanceof PointToken) {
        addPointToken(n, child)
      }
    } else {
      throw new Error(`Unexpected hyperscript child object: ${child}`)
    }
  }

  for (const child of children.flat(Infinity)) {
    addChild(child)
  }

  return nodes
}

/**
 * Create an anchor token.
 */

export function createAnchor(
  tagName: string,
  attributes: { [key: string]: any },
  children: any[]

View on GitHub (pinned to 72a37c701e)

Solutions

  1. Filter children: remove null/undefined/booleans before passing to hyperscript tags
  2. Ensure children are strings, numbers, element/text tags, or token tags (<anchor/>, <focus/>, <cursor/>)
  3. Check the custom creators object if you replaced default child handling

Example fix

// before
<element>{cond ? <text>hi</text> : null}</element>
// after
<element>{cond ? <text>hi</text> : <text />}</element>
Defensive patterns

Strategy: validation

Validate before calling

const kids = children.flat(Infinity).filter(
  c => c != null && typeof c !== 'boolean'
)
// pass kids to hyperscript tags

Type guard

const isHyperscriptChild = (c: any): boolean =>
  typeof c === 'string' ||
  typeof c === 'number' ||
  (typeof c === 'object' && c !== null && ('text' in c || 'children' in c || 'type' in c))

Try / catch

null

Prevention

When it happens

Trigger: Passing null/undefined, booleans, plain objects, or arbitrary class instances as children in slate-hyperscript JSX, e.g. <element>{null}</element> with certain creator versions or a custom creators object that doesn't handle a type.

Common situations: Conditionally rendering children that evaluate to unexpected values in hyperscript tests; spreading arrays containing undefined; custom creators replacing default handlers.

Related errors


AI-assisted analysis of ianstormtaylor/slate@72a37c701e (2026-08-27). Data as JSON: /api/errors/4dc1c790f929cf7b. Report an issue: GitHub.