codex-team/editor.js · error · Error
Incorrect data passed to the render() method
Error message
Incorrect data passed to the render() method
What it means
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.
Source
Thrown at src/components/modules/api/blocks.ts:206
this.Editor.Toolbar.close();
}
/**
* Clear Editor's area
*/
public async clear(): Promise<void> {
await this.Editor.BlockManager.clear(true);
this.Editor.InlineToolbar.close();
}
/**
* Fills Editor with Blocks data
*
* @param {OutputData} data — Saved Editor data
*/
public async render(data: OutputData): Promise<void> {
if (data === undefined || data.blocks === undefined) {
throw new Error('Incorrect data passed to the render() method');
}
/**
* Semantic meaning of the "render" method: "Display the new document over the existing one that stays unchanged"
* So we need to disable modifications observer temporarily
*/
this.Editor.ModificationsObserver.disable();
await this.Editor.BlockManager.clear();
await this.Editor.Renderer.render(data.blocks);
this.Editor.ModificationsObserver.enable();
}
/**
* Render passed HTML string
*
* @param {string} data - HTML string to renderView on GitHub (pinned to 5f45dabbe5)
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
Example fix
// before
editor.blocks.render(JSON.parse(localStorage.getItem('draft')));
// after
const raw = localStorage.getItem('draft');
const data = raw ? JSON.parse(raw) : null;
editor.blocks.render(data && Array.isArray(data.blocks) ? data : { blocks: [] }); Defensive patterns
Strategy: type-guard
Validate before calling
const isRenderable = (d: unknown): d is OutputData => !!d && Array.isArray((d as OutputData).blocks); if (!isRenderable(data)) data = { blocks: [] }; await editor.blocks.render(data); Type guard
const isOutputData = (d: unknown): d is OutputData => typeof d === 'object' && d !== null && Array.isArray((d as OutputData).blocks);
Try / catch
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; } Prevention
- Validate loaded JSON shape before render
- Default to { blocks: [] } for missing drafts
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- «holderId» and «holder» param can't assign at the same time.
- Tool «${toolName}» must be a constructor function or an obje
- Unable to move Block down since it is already the last
- Unable to move Block up since it is already the first
- Block with id "${id}" not found
AI-assisted analysis of codex-team/editor.js@5f45dabbe5 (2026-08-27).
Data as JSON: /api/errors/d176af9df4880a55.
Report an issue: GitHub.