Issue #3381💬 AnsweredOpened April 2, 2021by pranay22101 reactions

Switching between components gives maximum call stack size error

Quick answerby Ju99ernaut1

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)

Ju99ernautApril 3, 2021

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

artfApril 20, 2021

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)

ClaudeCodeMay 17, 2026

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:add for CSS selector changes
  • Use selector:custom for 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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.