<> is introduced at the beginning editor.getHtml()
I whittled the json down a quite a bit, and noticed there is some possibly invalid JSON being generated as output? Its like the introduction of the escaped double quotes is off slightly. JSON.stringify and JSON.parse don't seem to care about it, but theres something going on.
Read full answer below βQuestion
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Chrome Version 121.0.6167.185 (Official Build) (64-bit)
Reproducible demo link
https://jsfiddle.net/ja50kzne/4/
Describe the bug
How to reproduce the bug?
- I had a webpage from a previous version of grapesJS that loads into grapes correctly. You can see this in the fiddle. The latest version of GrapesJS "created" the JSON seen in the fiddle. I did not manipulate it.
- Notice that grapesJS does load, no errors in the console.
- When performing editor.getHtml (for db storage), I see that there is an empty element
<>being introduced - Note the console.log
What is the expected behavior?
I expect to not see <> at the start of the string from editor.getHtml()
What is the current behavior?
I see <> upon using .editor.getHtml()
I want to reiterate that I have not messed with the JSON. If there is something in there, it was generated by a previous version of grapesJS.
If is necessary to execute some code in order to reproduce the bug, paste it here below:
See fiddle https://jsfiddle.net/ja50kzne/4/
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (4)
I whittled the json down a quite a bit, and noticed there is some possibly invalid JSON being generated as output?
"components":[
{
"name":"Row",
"droppable":".cell",
"resizable":{
"tl":0,
"tc":0,
"tr":0,
"cl":0,
"cr":0,
"bl":0,
"br":0,
"minDim":1
},
"classes":[
"row"
],
"attributes":{
"id":"ik4zj"
}
},
{
"type":"text",
"content":"<p style=\\""text-align":"center;\\""><em>With special appreciation for our <a href=\\""https":" target=\\""_blank\\"">Major Sponsors</a>:</em></p>\\n",
"attributes":{
"id":"in5ko"
}
}
]
Its like the introduction of the escaped double quotes is off slightly. JSON.stringify and JSON.parse don't seem to care about it, but theres something going on.
The root component of the page should be a wrapper, in your case is a textnode (eg. this might break a lot of stuff), with an empty tagName (the reason behind <>) and for some reason content: "undefined"(?)
<img width="377" alt="Screenshot 2024-02-22 at 00 44 33" src="https://github.com/GrapesJS/grapesjs/assets/11614725/0e76b02e-097b-463f-a921-33250850e3f2">
I wouldn't even expect it to load but the editor is making some slight enforcements on the root component but type and tagName are extendable so can not be enforced.
Can't really help here, I can only suggest updating the JSON manually or via script. This doesn't seem to be a behavior of any previous version, so might also be related to some custom code.
This is what was coming out of Grapes 0.18.4, therefor it was generated by grapes. I would expect if content was "undefined", grapes would either strip it or ignore it. For now i'm just stripping the <> out on my end, but I thought I'd just share it with you.
Thanks for reporting this, @mitcht.
Great question about <> is introduced at the beginning editor.getHtml(). The recommended approach with GrapesJS 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 #4094
When drag and drop block into editor in Chrome, not able to drag and drop block
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 97.0.4692.71 (Official Build) (64-...
Issue #4921
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 110.0.5481.78 (Official Bui...
Issue #6116
asDocument not working as expected
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 128 Reproducible demo link https://...
Issue #5442
After applying the text color not able to set the background color
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? chrome Reproducible demo link https://jsfi...
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.