BUG: TypeError: e.getRoot is not a function (Race condition in Style Manager)
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
All browsers (Chrome, Safari, Firefox, Edge)
Reproducible demo link
https://jsfiddle.net/saeedhbi/powxyjdq/3/
Describe the bug
How to reproduce the bug?
- Initialize a GrapeJS editor
- Select a component in the canvas
- Quickly delete the component (press Delete key or use delete command)
- Style Manager's debounced update callback executes after component is destroyed
- Observe
TypeError: e.getRoot is not a function
What is the expected behavior? The Style Manager should validate that components are still valid before attempting to call methods on them. Either:
- Filter out destroyed/invalid components before processing
- Add try-catch guards around component method calls
- Check component validity (e.g.,
typeof component.getRoot === 'function') before invoking methods
No error should be thrown when components are removed during async style updates.
What is the current behavior?
GrapeJS throws TypeError: e.getRoot is not a function when the Style Manager attempts to update styles on a component that has been destroyed or removed from the DOM. This is a race condition between component selection/style updates and component removal/destruction.
Error messages:
Chrome:
TypeError: e.getRoot is not a function
Safari:
TypeError: e.getRoot is not a function. (In 'e.getRoot()', 'e.getRoot' is undefined)
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (2)
Similar to https://github.com/GrapesJS/grapesjs/issues/6705
I'm not able to create that kind of race condition (eg. select and remove via API) and in your example is checking getRoot on a component, but there is no such a method on the Component API
Same as https://github.com/GrapesJS/grapesjs/issues/6705#issuecomment-3921025039, the issue was in our external library that was using GrapeJS and since had same situation like the issue 6705, I will close it. Thank you for your review.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #6705
BUG: TypeError: Cannot read properties of undefined (reading 'toLowerCase') in keyboard handler
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? All browsers (Chrome, Safari, Firefox, Edg...
Issue #6458
BUG: sector.setName doesn't work
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://jsfi...
Issue #4310
BUG: Style Manager is inaccurate when using combined CSS selectors which contains "bout" and componentFirst = true
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 100 Reproducible demo link https://...
Issue #5487
BUG: Style Manager doesn't display multiple rules for the same class
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Firefox Reproducible demo link https://jsf...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.