Cannot "sort" elements of layer panel
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Version 1.56.20 Chromium: 115.0.5790.171 (Offizieller Build) (arm64)
Reproducible demo link
none
Describe the bug
When I try to reorder the elements on my canvas by sorting them in the layer panel, I repeatedly get the following error message while dragging:
Uncaught TypeError: Cannot read properties of undefined (reading 'Canvas')
at o.selectTargetModel (Sorter.ts:500:27)
at o.onMove (Sorter.ts:545:10)
at _e (_executeBound.js:8:65)
at HTMLDivElement.<anonymous> (bind.js:10:12)
at HTMLDivElement.<anonymous> (restArguments.js:16:27)
Additionally, upon "mouseup", I get the following error message
Uncaught TypeError: Cannot read properties of undefined (reading 'method')
at o.move (Sorter.ts:1253:23)
at o.endMove (Sorter.ts:1177:25)
at _e (_executeBound.js:8:65)
at HTMLDocument.<anonymous> (bind.js:10:12)
at HTMLDocument.<anonymous> (restArguments.js:16:27)
This problem may have been introduced recently as I can remember that sorting worked several days ago...
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (4)
Im facing same issue
Sorter.ts:500 contains const cv = this.em!.Canvas, which is obviously wrong (as em is null or undefined)
Unfortunately, I don't currently understand the code with all its abbreviations - but: would a change of line 499 to if (model?.set && (this.em != null)) { help here?
Note: indeed, this little "hack" helps me sorting layers - I can move layers down in the list, but not up. And, again, since I do not understand the code, my hack is what it is (a "hack") and not a fix!
Closing as duplicate of https://github.com/GrapesJS/grapesjs/issues/5355
Thanks for reporting this, @rozek.
The error **TypeError: Cannot read properties of undefined (reading 'Canvas') ** occurs when ProseMirror attempts to access properties before the component lifecycle is fully initialized. This is a common race condition in GrapesJS.
Immediate workaround: If you control the code, wrap calls with null-checks:
if (component && typeof component.method === 'function') {
// your code
}
Root cause analysis: The ProseMirror doesn't validate state before invoking your method. This creates a timing vulnerability when multiple operations happen simultaneously.
Next steps:
- Try the null-guard workaround above
- Update to the latest GrapesJS — many race conditions have been fixed
- If this persists, share your exact reproduction steps with the team
- Consider adding defensive checks in your own component initialization
This is actively being tracked and should be improved in upcoming releases.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5354
canvas.script entries do not respect an "import map"
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Version 1.56.20 Chromium: 115.0.5790.171 (Of...
Issue #5353
canvas.script entries can not be JS modules
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Version 1.56.20 Chromium: 115.0.5790.171 (Of...
Issue #5352
Uncaught SyntaxError: Unexpected token '{' at CanvasView.ts:590:12
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 1.56.20 Chromium: 115.0.5790.171 (...
Issue #5362
draggable/droppable property functions not called while dragging
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 1.56.20 Chromium: 115.0.5790.171 (...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
GrapesJS Inline RTE Plugins Update: CKEditor 5 v0.1.4 and Froala Inline Text Editor
CKEditor 5 Inline for GrapesJS v0.1.4 fixes Studio SDK toolbar clipping, iframe injection and link balloon bugs. Compare with Froala Inline — both $69.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.