Stop function of all commands are getting executed before the actual run command.
Hi @slellampati, I'm sorry this answer might be a little late to the party, but I've just stumbled upon the same behaviour & discovered this issue. To answer the question: GrapesJS's buttons have an active event listener, which deactivates all buttons in a panel in which a button is activated, causing their stop comma...
Read full answer below ↓Question
I created 3 custom button(edit, preview, save) and all those have run and stop methods. When i click on any button, it triggers the run command of that button but before that stop function of other buttons are executed.
// Edit code button
panelManager.addButton('options', {
id: 'edit-code',
className: 'fa fa-edit',
command: {
// @ts-ignore
run(editor: GrapesJS, sender: {}) {
log.debug('Edit opened');
},
stop(editor: GrapesJS) {
log.debug('Edit complete');
}
},
attributes: { title: 'Edit code' },
active: false
});
// Add preview button
panelManager.addButton('options', {
id: 'custom-preview',
label: 'Preview',
command: {
// @ts-ignore
run(editor: GrapesJS, sender: {}) {
log.debug('Edit opened');
},
stop(editor: GrapesJS) {
log.debug('Edit complete');
}
},
attributes: { title: 'Preview' },
active: false
});
// Add save button
panelManager.addButton('options', {
id: 'save',
label: 'Save',
command: {
run(editor: GrapesJS) {
log.debug('saved');
},
stop(editor: GrapesJS) {
log.debug('Save complete');
}
},
attributes: { title: 'Save' },
active: false
});
When i click on Edit, below is the console output
[Email Template] Stop preview
[Email Template] Save complete
[Email Template] Edit opened
When Edit button closed (stop command)
[Email Template] Edit complete
What is causing the other stop commands to trigger first even when i dont have any event listeners?
Answers (2)
Hi @slellampati,
I'm sorry this answer might be a little late to the party, but I've just stumbled upon the same behaviour & discovered this issue.
To answer the question: GrapesJS's buttons have an active event listener, which deactivates all buttons in a panel in which a button is activated, causing their stop commands to be run
I started a similar discussion on another issue, if you're interested in having more details.
Cheers :)
You can add a different context: 'eg. save-button' to your buttons to detach them from this default behavior (by default buttons share the same context)
There is actually a tiny reference in getting started guide about this: https://grapesjs.com/docs/getting-started.html#panels-buttons
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1127
Command running multiple times
Hello Folks, I need your help.I created a custom button on the commands Panel to publish the site created from Grapes.When i click on it, i...
Issue #690
Preview Command bug: exit the preview mode will run the sw-visibility command, when the sw-visibility stopped before go to preview mode.
Hi @artf , The case is "switch-visibility" command stopped, then click the preview button or trigger preview command, it will go to preview...
Issue #2046
[QUESTIONS] How to disable Scripts inside the editor?
Hi @artf , I need to disable all the scripts (component scripts and other scripts) inside the editor, and scripts should run only when we c...
Issue #2350
[Question] How do I add elements/sectors to views container using a custom button in the Panel
I have added a custom button to the Panel as below: const pm = editor.Panels; pm.addButton('views', { id: 'customButton', className: '', co...
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
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.
Tutorial
GrapesJS vs Webflow vs Builder.io vs Puck: Which Visual Builder to Choose in 2026
A practitioner's 2026 comparison of GrapesJS, Webflow, Builder.io, and Puck — pricing, AI features, lock-in, and a one-line rule for picking the right one
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.