You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -28,47 +28,137 @@ See https://wxt.dev/guide/essentials/config/browser-startup.html#persist-data
28
28
29
29
## My component library doesn't work in content scripts!
30
30
31
-
Component libraries place their CSS in the document's `<head>` by default. When using `createShadowRootUi`, your UI is isolated from the document's styles because it's inside a ShadowRoot.
32
-
33
-
To fix this, you need to tell your component library to insert it's CSS inside the shadow root. Here's the docs for a couple of popular libraries:
34
-
35
-
- React
36
-
- Ant Design: [`StyleProvider`](https://ant.design/docs/react/compatible-style#shadow-dom-usage)
37
-
- Mantine: [`MantineProvider#getRootElement` and `MantineProvider#cssVariablesSelector`](https://mantine.dev/theming/mantine-provider/)
38
-
39
-
> If your library isn't listed above, try searching it's docs/issues for "shadow root", "shadow dom", or "css container".
40
-
41
-
`createShadowRootUi` provides it's own `<head>` element inside the shadow root, so that were you should tell the library to add the CSS. Here's an example with Ant Design:
This is usually caused by one of two things (or both) when using `createShadowRootUi`:
32
+
33
+
1. Styles are added outside the `ShadowRoot`
34
+
35
+
:::details
36
+
Some component libraries manually add CSS to the page by adding a `<style>` or `<link>` element. They place this element in the document's `<head>` by default. This causes your styles to be placed outside the `ShadowRoot` and it's isolation blocks the styles from being applied to your UI.
68
37
69
-
Note that this doesn't effect all component libraries, just ones that inject CSS themselves rather than having you import their CSS. This approach is more prevailent in the React community, but not limited to it. That's why only React libraries are listed above. Vuetify, for example, works just fine because you import its CSS - WXT picks up on this and the CSS is added inside the shadow root automatically:
38
+
When a library does this, **you need to tell the library where to put its styles**. Here's the documentation for a few popular component libraries:
39
+
40
+
- Ant Design: [`StyleProvider`](https://ant.design/docs/react/compatible-style#shadow-dom-usage)
41
+
- Mantine: [`MantineProvider#getRootElement` and `MantineProvider#cssVariablesSelector`](https://mantine.dev/theming/mantine-provider/)
42
+
43
+
> If your library isn't listed above, try searching it's docs/issues for "shadow root", "shadow dom", or "css container". Not all libraries support shadow DOMs, you may have to open an issue to request this feature.
import'vuetify/styles'; // <-- This line imports the CSS, just like importing a .css file
73
-
import { createVuetify } from'vuetify';
74
-
```
67
+
:::
68
+
69
+
2. UI elements are added outside the `ShadowRoot`
70
+
71
+
::::::details
72
+
This is mostly caused by `Teleport` or `Portal` components that render an element somewhere else in the DOM, usually in the document's `<body>`. This is usually done for dialogs or popover components. This renders the element is outside the `ShadowRoot`, so styles are not applied to it.
73
+
74
+
To fix this, **you need to both provide a target to your app AND pass the target to the `Teleport`/`Portal`**.
75
+
76
+
First, store the reference to the `ShadowRoot`'s `<body>` element (not the document's `<body>`):
Both issues have the same cause: the library puts something outside the `ShadowRoot`, and the `ShadowRoot`'s isolation prevents CSS from being applied to your UI.
163
+
164
+
Both issues have the same fix: tell the library to put elements inside the `ShadowRoot`, not outside it. See the details above for more information and example fixes for each problem.
0 commit comments