V0.16.27 - Style/ID disappear when nested span
Hi Benjamin, the bug was already fixed (when you report a bug, ensure to have the latest version)
Read full answer below ↓Question
Version: 0.16.27
Are you able to reproduce the bug from the demo?
[ ] Yes [ ] No [X] Video but no demo
What is the expected behavior?
Add as many nested span elements as necessary and preserve their style/ID.
What is the current behavior?
From two nested span elements, style/ID of parent span elements disappear.
Are you able to attach screenshots, screencasts or a live demo?
[X] Yes (attach) [ ] No
TextEditor.vue
// ...
methods: {
onButtonClick (action, value = '') {
try {
const selected = this.editor.getSelected()
const rte = selected.view.activeRte
let style = `${action}:${value};`
switch (action) {
case 'showCustomizationPanel':
this.customizationPanel = value
break
case 'text-align':
this.mergeComponentStyle(selected, {
[action]: value
})
break
case 'font-size':
case 'line-height':
style += (action === 'font-size') ? 'line-height:100%;' : ''
rte.insertHTML(
`<span style="${style}">${rte.selection()}</span>`
)
break
default:
rte.exec(action, value)
}
} catch (error) {
this.showError(error, 'onButtonClick()')
}
},
/**
* Defines default style on the added component
* @see {@link https://grapesjs.com/docs/api/component.html#getstyle|Get style}
* @param {object} component
* @returns {void}
*/
setDefaultStyle (component) {
const {
'font-family': fontFamily = '',
'font-size': fontSize = ''
} = component.getStyle()
if (!fontFamily) {
this.mergeComponentStyle(component, {
'font-family': this.font.familyPartner[this.partnerId] || this.font.familyDefault
})
}
if (!fontSize) {
this.mergeComponentStyle(component, {
'font-size': this.font.sizePartner[this.partnerId] || this.font.sizeDefault,
'line-height': '100%'
})
}
},
/**
* Merges GrapesJS component style
* @see {@link https://grapesjs.com/docs/api/component.html#getstyle|Get style}
* @see {@link https://grapesjs.com/docs/api/component.html#setstyle|Set style}
* @param {object} component
* @param {object} style
* @returns {void}
*/
mergeComponentStyle (component, style) {
component.setStyle({
...component.getStyle(),
...style
})
}
}
// ...
Answers (2)
Hi Benjamin, the bug was already fixed (when you report a bug, ensure to have the latest version)
Thanks for reporting this, @bgrand-ch.
The issue with v0.16.27 - Style/ID disappear when nested span appears to be a race condition or state management timing problem. This typically happens when component lifecycle events and DOM modifications overlap, creating an inconsistent state.
What to try:
- Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
// your operation here
}, 0);
-
Check initialization order — make sure components are fully loaded before you interact with them
-
Use the editor's event system — listen to completion events:
editor.on('component:mount', (component) => {
// safe to interact with component here
});
Recommended next steps:
- Test with the latest GrapesJS version if you haven't
- Provide a minimal reproducible example (CodeSandbox) — this helps the team identify the root cause faster
- Include GrapesJS version, browser, and console errors in your report
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3289
(0.16.41) Components have lost their styles
Version: 0.16.41 Are you able to reproduce the bug from the demo? [X] Yes [ ] No What is the expected behavior? 1) Copy selected parent com...
Issue #5173
editor.Css.setRule API not working as expected, it is not updating the rule existing rule.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 112.0.5615.137 (Official Build) (a...
Issue #6458
sector.setName doesn't work
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://jsfi...
Issue #3125
linear-gradient CSS does weird things to background-image
Version: 0.16.27 Are you able to reproduce the bug from the demo? [x] Yes [ ] No What is the expected behavior? When adding background-imag...
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.