sonner icon indicating copy to clipboard operation
sonner copied to clipboard

Shadow DOM support

Open STiXzoOR opened this issue 1 year ago • 4 comments

Describe the feature / bug 📝:

I have a project where i use sonner in a web extension, but recently I moved the rendering to the shadow dom. Then I noticed that the toasts where not rendering as they were suppose to. After checking the source code and styles, it seems that the styles are loaded in the document's head and therefore in the shadow dom are not available.

Steps to reproduce the bug 🔁:

Render toasts in shadow dom. Styles are missing from the components.

As a workaround i copied the styles to my codebase and i load them manually, but it would be a great if we have the styles available as a loadable file instead of loading them automatically to have more control over where we want to load them.

STiXzoOR avatar Mar 04 '24 14:03 STiXzoOR

I also encountered this problem. It should be the problem of tailwind. Have you solved it?

kurorinto avatar May 09 '24 07:05 kurorinto

Facing the same issue. Looking forward to a solution.

scarletczen avatar Jun 17 '24 10:06 scarletczen

Facing the same issue. Looking forward to a solution.

I solved it, the solution is to add components'style and twcss to ShadowDOM.

export const getStyle = () => {
  const style = document.createElement("style")
  style.textContent = cssText
    .replaceAll(":root", ":root,:host(plasmo-csui)")
    .concat(sonnerCssText)
  return style
}

view details: https://github.com/kurorinto/rozone/blob/main/src/contents/index.tsx#L14

kurorinto avatar Jul 26 '24 07:07 kurorinto

Thanks @kurorinto

scarletczen avatar Jul 26 '24 16:07 scarletczen