ianstormtaylor/slate · error · Error

The <text> hyperscript tag can only contain text conten

Error message

    The <text> hyperscript tag can only contain text content as children.

What it means

Thrown by the <text> hyperscript tag when the resolved single child node is not a Slate Text node — i.e. an element tag (or non-text node) was nested inside <text>.

Source

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

  attributes: { [key: string]: any },
  children: any[]
): Text {
  const nodes = resolveDescendants(children)

  if (nodes.length > 1) {
    throw new Error(
      `The <text> hyperscript tag must only contain a single node's worth of children.`
    )
  }

  let [node] = nodes

  if (node == null) {
    node = { text: '' }
  }

  if (!Text.isText(node)) {
    throw new Error(`
    The <text> hyperscript tag can only contain text content as children.`)
  }

  // COMPAT: If they used the <text> tag we want to guarantee that it won't be
  // merge with other string children.
  STRINGS.delete(node)

  Object.assign(node, attributes)
  return node
}

/**
 * Create a top-level `Editor` object.
 */

export const createEditor =
  (makeEditor: () => Editor) =>
  (

View on GitHub (pinned to 72a37c701e)

Solutions

  1. Use <element> for element nodes and <text> only for text content
  2. Ensure custom creators map 'text' to a text-producing creator

Example fix

// before
<text>
  <element><text>hi</text></element>
</text>
// after
<element>
  <text>hi</text>
</element>
Defensive patterns

Strategy: type-guard

Validate before calling

import { Text } from 'slate'
const nodes = resolveDescendants(children)
if (nodes.some(n => !Text.isText(n))) throw new Error('<text> children must be text')

Type guard

const allText = (nodes: Node[]): boolean => nodes.every(Text.isText)

Try / catch

null

Prevention

When it happens

Trigger: Writing <text><element>...</element></text> or otherwise nesting an element creator inside the text tag so resolveDescendants yields an Element node.

Common situations: Fixture typos: wrapping paragraphs in <text> instead of <element>; mixing up tag names in custom creator setups.

Related errors


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