GrapesJS / GrapesJS/grapesjs

BUG: Create and destroy repeatedly throws error

Open
#6,494 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
26.2k
Forks
4.6k
Avg merge
2d 21h
Merged PRs (30d)
6

Description

### GrapesJS version

- [x] I confirm to use the latest version of GrapesJS

### What browser are you using?

Chrome

### Reproducible demo link

https://codepen.io/Harshsne/pen/QwwLjBQ

### Describe the bug

**How to reproduce the bug?**
1. Click Create and then Destroy repeatedly and rapidly.

Upon debugging, I found that the error occurs due to the following code:

1. undefined 'allcomponents' error is due to : (editor.select code.)
```
var wrapper = editor.DomComponents.getWrapper();
**editor.select(wrapper);**
```

2. undefined 'lastcomponent' error:

```
editor.addComponents({
type: 'text',
highlightable: false,
selectable: false,
droppable: false,
draggable: false,
removable: false,
copyable: false,
attributes: { class: 'textbox', "data-placeholder": "Insert your text here" },
content: "fgfghfg",
styles: `.textbox{word-break:break-word;}`,
style: { "height": "110px", "outline": "none !important", "padding": '5px', "color": "grey" }
});

```

Adding the style to the component triggers the stylable:change event, which throws an error if your side function is still running and you click Destroy during that time.

![Image](https://github.com/user-attachments/assets/59cbde1c-23f9-45d6-b8a3-6b2b7aebbfe8)
I attempted to handle this on my side, but the fix didn’t work.
Any suggestions?

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.