{"record":{"id":"d176af9df4880a55","repo":"codex-team/editor.js","slug":"incorrect-data-passed-to-the-render-method","errorCode":null,"errorMessage":"Incorrect data passed to the render() method","messagePattern":"Incorrect data passed to the render\\(\\) method","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/components/modules/api/blocks.ts","lineNumber":206,"sourceCode":"    this.Editor.Toolbar.close();\n  }\n\n  /**\n   * Clear Editor's area\n   */\n  public async clear(): Promise<void> {\n    await this.Editor.BlockManager.clear(true);\n    this.Editor.InlineToolbar.close();\n  }\n\n  /**\n   * Fills Editor with Blocks data\n   *\n   * @param {OutputData} data — Saved Editor data\n   */\n  public async render(data: OutputData): Promise<void> {\n    if (data === undefined || data.blocks === undefined) {\n      throw new Error('Incorrect data passed to the render() method');\n    }\n\n    /**\n     * Semantic meaning of the \"render\" method: \"Display the new document over the existing one that stays unchanged\"\n     * So we need to disable modifications observer temporarily\n     */\n    this.Editor.ModificationsObserver.disable();\n\n    await this.Editor.BlockManager.clear();\n    await this.Editor.Renderer.render(data.blocks);\n\n    this.Editor.ModificationsObserver.enable();\n  }\n\n  /**\n   * Render passed HTML string\n   *\n   * @param {string} data - HTML string to render","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/codex-team/editor.js/blob/5f45dabbe5690b7033b2f9047d3985add5045fdd/src/components/modules/api/blocks.ts#L188-L224","documentation":"BlocksAPI.render(data) requires a full saved document object with a `blocks` array; it validates that neither `data` nor `data.blocks` is undefined and throws otherwise. It exists to catch malformed saved data before the renderer runs.","triggerScenarios":"Calling `editor.blocks.render(undefined)`, `editor.blocks.render({})`, or passing a JSON-parsed payload whose blocks field is missing (e.g. wrong storage key or hand-mangled save file).","commonSituations":"Loading from localStorage where the saved item is absent or corrupt; backend returns `{time: ...}` without blocks; passing `editor.save()` output that was truncated or re-wrapped.","solutions":["Verify the payload shape before calling render (data && Array.isArray(data.blocks))","Fix the producer: ensure save()/backend actually stores {blocks: [...]}","Default to empty document: render({ blocks: [] }) when data is missing"],"exampleFix":"// before\neditor.blocks.render(JSON.parse(localStorage.getItem('draft')));\n// after\nconst raw = localStorage.getItem('draft');\nconst data = raw ? JSON.parse(raw) : null;\neditor.blocks.render(data && Array.isArray(data.blocks) ? data : { blocks: [] });","handlingStrategy":"type-guard","validationCode":"const isRenderable = (d: unknown): d is OutputData => !!d && Array.isArray((d as OutputData).blocks); if (!isRenderable(data)) data = { blocks: [] }; await editor.blocks.render(data);","typeGuard":"const isOutputData = (d: unknown): d is OutputData => typeof d === 'object' && d !== null && Array.isArray((d as OutputData).blocks);","tryCatchPattern":"try { await editor.blocks.render(data); } catch (e) { if (e instanceof Error && e.message.includes('render() method')) { await editor.blocks.render({ blocks: [] }); return; } throw e; }","preventionTips":["Validate loaded JSON shape before render","Default to { blocks: [] } for missing drafts"],"tags":["render","validation","output-data","editorjs"],"backgroundTag":"schema-validation-failed","analyzedSha":"5f45dabbe5690b7033b2f9047d3985add5045fdd","analyzedAt":"2026-08-27T22:50:23.124Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}