{"record":{"id":"cae0707caf805b4e","repo":"ianstormtaylor/slate","slug":"slate-initialvalue-is-invalid-expected-a-list-o","errorCode":null,"errorMessage":"[Slate] initialValue is invalid! Expected a list of elements but got: ${Scrubber.stringify(\n          initialValue\n        )}","messagePattern":"\\[Slate\\] initialValue is invalid! Expected a list of elements but got: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/slate-react/src/components/slate.tsx","lineNumber":40,"sourceCode":"  children: React.ReactNode\n  onChange?: (value: Descendant[]) => void\n  onSelectionChange?: (selection: Selection) => void\n  onValueChange?: (value: Descendant[]) => void\n}) => {\n  const {\n    editor,\n    children,\n    onChange,\n    onSelectionChange,\n    onValueChange,\n    initialValue,\n    ...rest\n  } = props\n\n  // Run once on first mount, but before `useEffect` or render\n  React.useState(() => {\n    if (!Node.isNodeList(initialValue)) {\n      throw new Error(\n        `[Slate] initialValue is invalid! Expected a list of elements but got: ${Scrubber.stringify(\n          initialValue\n        )}`\n      )\n    }\n\n    if (!Editor.isEditor(editor)) {\n      throw new Error(\n        `[Slate] editor is invalid! You passed: ${Scrubber.stringify(editor)}`\n      )\n    }\n\n    editor.children = initialValue\n    Object.assign(editor, rest)\n  })\n\n  const { selectorContext, onChange: handleSelectorChange } =\n    useSelectorContext()","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate-react/src/components/slate.tsx#L22-L58","documentation":"The <Slate> React component validates on first mount that initialValue is a valid Node[] (list of elements). If it is not (wrong shape, undefined, a single node instead of an array, malformed JSON), it throws immediately so the editor never mounts with a broken document.","triggerScenarios":"<Slate editor={editor} initialValue={initialValue}> where initialValue is not an array of valid Slate nodes — e.g. undefined, an object, an array of strings, or a single element instead of a list.","commonSituations":"Fetching initial content asynchronously and passing it before the fetch resolves (undefined); restoring from localStorage/JSON with corrupted or old-format data; migration from another editor format (HTML string, ProseMirror doc) without converting to Slate nodes.","solutions":["Pass a valid default like initialValue=[{ type: 'paragraph', children: [{ text: '' }] }] and swap in fetched content later via editor.children assignment","Validate/normalize persisted JSON with Node.isNodeList (or a schema normalizer) before rendering <Slate>","Convert foreign formats (HTML/Markdown) to a Slate node tree before mounting"],"exampleFix":"// before\n<Slate editor={editor} initialValue={savedDoc}> // savedDoc may be undefined/corrupt\n\n// after\nconst initialValue = Node.isNodeList(savedDoc)\n  ? savedDoc\n  : [{ type: 'paragraph', children: [{ text: '' }] }]\n<Slate editor={editor} initialValue={initialValue}>","handlingStrategy":"validation","validationCode":"const safeValue = Node.isNodeList(initialValue)\n  ? initialValue\n  : [{ type: 'paragraph', children: [{ text: '' }] }]\n<Slate editor={editor} initialValue={safeValue}>","typeGuard":"const isValidValue = (v: unknown): v is Descendant[] => Node.isNodeList(v)","tryCatchPattern":"try { render(<Slate editor={e} initialValue={v}/>) } catch (err) { if (/initialValue is invalid/.test(err.message)) fallbackToDefault() else throw err }","preventionTips":["Always provide a fallback default document for async/loaded content","Normalize persisted JSON through a validator before mounting","Write a migrate() step for stored documents across schema versions"],"tags":["initial-value","validation","react","document","slate"],"backgroundTag":"invalid-document-structure","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}