Clone page prompt 'Converting circular structure to JSON'
In addition to the above method, is there any other way to copy the page?
Read full answer below βQuestion
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Chrome 129.0.6668.101
Reproducible demo link
Describe the bug
How to reproduce the bug?
open https://grapesjs.com/demo
run this script in DevTools:
const page = editor.Pages.getSelected();
const component = page?.getMainComponent()?.clone();
editor.Pages.add({
name: '11111',
component,
}, {
select: true,
});
What is the expected behavior?
Successfully copied without error
What is the current behavior?
Successfully copied with error:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'o'
| property 'opts' -> object with constructor 'Object'
| property 'el' -> object with constructor 'HTMLHeadElement'
--- property '__gjsv' closes the circle
at JSON.stringify (<anonymous>)
at o.storeData ([email protected]:2:1015087)
at o.<anonymous> ([email protected]:2:1014457)
at [email protected]:2:999571
at Object.next ([email protected]:2:999676)
at [email protected]:2:998551
at new Promise (<anonymous>)
at Pv ([email protected]:2:998293)
at o.store ([email protected]:2:1014352)
at o.updateChanges ([email protected]:2:1008885)
<img width="472" alt="image" src="https://github.com/user-attachments/assets/14309772-7e8e-4ce2-ba14-7aefbed8614f">
Deep cloning can use lodash: https://lodash.com/docs/4.17.15#cloneDeep
Please do not use JSON.parse(JSON.stringify(t))
In addition, my page actually has a lot of elements, and it is not just a few simple pages like the demo.
I found that it was very stuck when copying. After successfully page?.getMainComponent()?.clone(), the page got stuck directly.
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (2)
In addition to the above method, is there any other way to copy the page?
Thanks for reporting this, @maxming2333.
Great question about Clone page prompt 'Converting circular structure to JSON'. The recommended approach with Components is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4855
Outline disappears after applying loadProjectData
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Brave last version Reproducible demo link...
Issue #4384
index.d.ts says that components must be Backbone.Collection<Component> but the docs say Component[] is also accepted
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? AnyReproducible demo link https://grapesjs.c...
Issue #5175
Move method is not working as expected
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://code...
Issue #4285
[Component's toolbar] Toolbar width not resizing correctly
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome v100.0.4896.127Reproducible demo link...
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
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
Tutorial
Preset DevFuture 2.0 β New Update Released
Preset continues evolving as a clean, production-ready starting point for building visual editors powered by GrapesJS
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.