Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Clone page prompt 'Converting circular structure to JSON' #6250

Closed
2 tasks done
maxming2333 opened this issue Oct 23, 2024 · 1 comment · Fixed by #6291
Closed
2 tasks done

BUG: Clone page prompt 'Converting circular structure to JSON' #6250

maxming2333 opened this issue Oct 23, 2024 · 1 comment · Fixed by #6291

Comments

@maxming2333
Copy link

maxming2333 commented Oct 23, 2024

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Chrome 129.0.6668.101

Reproducible demo link

https://grapesjs.com/demo

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)
image

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
@maxming2333
Copy link
Author

In addition to the above method, is there any other way to copy the page?

@artf artf linked a pull request Nov 5, 2024 that will close this issue
@artf artf closed this as completed in #6291 Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant