Issue #3561Opened June 23, 2021by AStoker0 reactions

FEAT: Enhanced Shadow DOM Support

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 (3)

artfJune 24, 20210 reactions

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, 20210 reactions

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, 20210 reactions

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.

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.