Issue #3561💬 AnsweredOpened June 23, 2021by AStoker0 reactions

Enhanced Shadow DOM Support

快速解答by artf

Hi @AStoker I don't understand what is the real issue with your example (aside not loading GrapesJS styles inside your shadow dom). If you're attaching shadow dom, obviously, you can't do this container: '#gjs', but you're still able to pass HTMLElements as you're already doing in your example, so what is the issue?

Read full answer below ↓

Question

What are you trying to add to GrapesJS? Better Shadow DOM support, allowing developers to render GrapesJS inside a Shadow element without having to specifically pass in elements rather than selectors in the configuration.

Describe your feature request detailed When currently using element selectors, GrapesJS simply uses the document query selector. This does not work when rendering inside a Shadow DOM, as the document isn't the shadow root. I would like to be able to define a shadow root so that anything GrapesJS does/needs is contained within the shadow root.

Example of using GrapesJS inside a ShadowDOM: https://jsfiddle.net/theandybob/s9bnhw30/

Is there an alternative at the latest version?

  • Yes (describe the alternative)
  • No

Is this related to an issue?

  • Yes (Give a link to the issue)
  • No

Answers (4)

artfJune 24, 2021

Hi @AStoker I don't understand what is the real issue with your example (aside not loading GrapesJS styles inside your shadow dom). If you're attaching shadow dom, obviously, you can't do this container: '#gjs', but you're still able to pass HTMLElements as you're already doing in your example, so what is the issue?

AStokerJune 24, 2021

The issue is that I must pass HTML elements everywhere and cannot use selectors. This can become cumbersome to write as I must now use the shadow Dom's query selector for every panel, every element, anything that we hook into GrapesJS. Additionally, if there were the concept of a container, it would significantly help isolate GrapesJS from accidentally interfering with other parts of an application. As more applications make use of components and custom elements, proper isolation between components is important. The fact that GrapesJS automatically pulls in font-awesome (from a CDN too) into the root of the page isn't ideal, as there could very easily be conflicting styles. If you are using Shadow DOM, you could pass the container to GrapesJS and it would put font-awesome within the Shadow DOM, appropriately isolating styles from other parts of the application.

AStokerJune 24, 2021

I updated the JSFiddle so you can see what we need to do to get styles within Shadow DOM. But unfortunately the CSS that's automatically added by GrapesJS exists on the body and is both polluting the global stylesheets and pointless due to GrapesJS being inside the Shadow DOM.

ClaudeCodeMay 17, 2026

Thanks for reporting this, @AStoker.

Great suggestion about FEAT: Enhanced Shadow DOM Support! While this specific feature isn't yet in the core API, there are several ways to achieve similar behavior.

Using the event system:

editor.on('component:update', (component) => {
  // your logic here
});

Alternative approaches:

  • Listen to selector:add for CSS selector changes
  • Use selector:custom for custom rules
  • Tap into the change:* events for fine-grained tracking
  • Build a plugin that extends the editor with this capability

Making it official: If this feature would benefit many users, consider opening a formal Feature Request on the GrapesJS repo with:

  • A detailed use case
  • Code example showing the desired behavior
  • Why this matters for your workflow

The core team is receptive to well-motivated feature requests backed by real use cases.

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.