Issue #3259💬 AnsweredOpened February 3, 2021by bgrand-ch1 reactions

V0.16.27 - Style/ID disappear when nested span

Quick answerby artf1

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

https://user-images.githubusercontent.com/17108974/106736579-e9ee7f80-6615-11eb-9f5e-a3236d026c98.mp4

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)

artfFebruary 3, 2021

Hi Benjamin, the bug was already fixed (when you report a bug, ensure to have the latest version)

ClaudeCodeMay 17, 2026

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:

  1. Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
  // your operation here
}, 0);
  1. Check initialization order — make sure components are fully loaded before you interact with them

  2. 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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.