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: asDocument not working as expected #6116

Closed
2 tasks done
SamMousa opened this issue Sep 3, 2024 · 5 comments
Closed
2 tasks done

BUG: asDocument not working as expected #6116

SamMousa opened this issue Sep 3, 2024 · 5 comments

Comments

@SamMousa
Copy link

SamMousa commented Sep 3, 2024

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Chrome 128

Reproducible demo link

https://jsfiddle.net/sammousa/bxgsdc12/11/

Describe the bug

How to reproduce the bug?

  1. Load an HTML string with a non empty <head>, using the option {asDocument: true}.
  2. Export the data via editor.getProjectData(), see that it contains the <head> content
  3. Load the exported data from 2 via editor.loadProjectData()
  4. Export the data via editor.getProjectData(), see that it does NOT the <head> content

What is the expected behavior?
I'd expect that this should always hold, maybe with the exception for some details like autogenerated ids.

const html1 = editor.getHtml();
const html2 = editor.loadProjectData(editor.getProjectData());
html1 === html2

What is the current behavior?
The head content is not loaded when using loadProjectData().

Code of Conduct

  • I agree to follow this project's Code of Conduct
@kanaihyakumar
Copy link

I've made some code changes that might help you achieve the desired behavior. Please check them out here: JSFiddle Example

It seems to match what you are looking for.

@SamMousa
Copy link
Author

SamMousa commented Sep 4, 2024

Thank you, but that's not really the point. I'm fully able to make a workaround, but that does not fix the bug.

The bug is that an export via getProjectData() followed by an import via loadProjectData() should result in the same state.

Furthermore the hack you propose actually writes directly to the canvas meaning that there's no guarantee it will remain untouched. (For example there's a styles configuration in the editor that will inject styles to the canvas' head)

@artf
Copy link
Member

artf commented Sep 4, 2024

The bug is that an export via getProjectData() followed by an import via loadProjectData() should result in the same state.

Yeah definitely not expected, we'll look into it.

Appreciate the easily reproducible steps on the demo 👍

@SamMousa
Copy link
Author

SamMousa commented Sep 4, 2024

I'm just starting to integrate this library.. just a heads up: more issues will follow, I make them as clear as I can and am always happy to implement my proposed fixes, I do often need some direction when several solution directions exist

@artf
Copy link
Member

artf commented Sep 4, 2024

Thanks @SamMousa detailed bug reports are always welcome.
If a direction is requested, we're happy to guide you 🙇‍♂️

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

No branches or pull requests

3 participants