Switching between components gives maximum call stack size error
I think arrays aren't the best method of storing page objects, so running array operations to get the page plus loading the page is probably too much for your call stack. You should consider loading the pages into memory only when you need them and store them in something like a database instead of an array. You can t...
Read full answer below ↓Question
Hey artf, I would like to thank you for building such a powerful tool for building customized CMS.
I'm implementing a new page feature in my project so I'm using your reference to switch between components but It gives me an error, Please can you guide me on how to build a new page on click add new button from the panel?
Uncaught RangeError: Maximum call stack size exceeded
at grapesjs:2
at grapesjs:2
at Te (grapesjs:2)
at Module.Ae (grapesjs:2)
at r.filter (grapesjs:2)
at r.where (grapesjs:2)
at Object.getSelector (grapesjs:2)
at Object.get (grapesjs:2)
at r.getAttributes (grapesjs:2)
at r.toJSON (grapesjs:2)
Here is my code
var pages = [];
function changePage(index) {
var page = { components: editor.getComponents(), style: editor.getStyle() };
pages.splice(index, 0, page);
console.log(pages)
loadPage();
}
function loadPage() {
var nextPage = pages[0];
editor.setComponents(nextPage.components);
editor.setStyle(nextPage.style);
}
Answers (3)
I think arrays aren't the best method of storing page objects, so running array operations to get the page plus loading the page is probably too much for your call stack. You should consider loading the pages into memory only when you need them and store them in something like a database instead of an array. You can try this plugin https://github.com/Ju99ernaut/grapesjs-template-manager
I'm not sure what is happening on your side but I'd suggest keeping an eye on #3206 as the built-in page manager is almost ready (I'll update that issue)
Thanks for reporting this, @pranay2210.
Great suggestion about Switching between components gives maximum call stack size error! While this specific feature isn't yet in the core API, there are several ways to achieve similar behavior.
Using the event system:
editor.on('component:update', (component) => {
// your logic here
});
Alternative approaches:
- Listen to
selector:addfor CSS selector changes - Use
selector:customfor custom rules - Tap into the
change:*events for fine-grained tracking - Build a plugin that extends the editor with this capability
Making it official: If this feature would benefit many users, consider opening a formal Feature Request on the GrapesJS repo with:
- A detailed use case
- Code example showing the desired behavior
- Why this matters for your workflow
The core team is receptive to well-motivated feature requests backed by real use cases.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3292
Is there a event per component before save which the component can listen to?
Much grateful to you for this library. Background: I am building an editor where I intend to define most of the components from an existing...
Issue #4503
Missing inline styles used by CKEditor when adding raw html components
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chromium v96 Reproducible demo link https:...
Issue #4225
BUG : The facebook plugin is not working in the grapes js
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome v9Reproducible demo link Not thereDes...
Issue #5156
Cannot drag drop in mobile screen even add grapejs-touch
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome, IOSReproducible demo link https://ww...
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
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
GrapesJS vs Webflow vs Tilda: What to Choose for Your Business in 2026
Choosing the right website platform in 2026 is no longer just about building a site
Tutorial
GJS Market 2.0 - Donations, Tracking, Labels and Better Product Discovery
We’ve rolled out a new set of GrapesJS marketplace updates across GJS Market, focused on improving how creators distribute products
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.