Replies: 3 comments 4 replies
-
This problem is same with any other UI component library. Like for example I've grown fond of headlessui components, I use that a lot, this package also has Dropdown like component known as Combobox, when I wanted to configure this in my content scripts, I also faced this same issue. From what I've debugged and scour through the github issues, Edit: |
Beta Was this translation helpful? Give feedback.
-
Would be nice to spread the awareness and have shadcn team fix this issue as well, because currently injecting the styles to the main document works,but messes up original website styles most of the time ;/ |
Beta Was this translation helpful? Give feedback.
-
https://wxt.dev/guide/resources/faq.html#my-component-library-doesn-t-work-in-content-scripts Very similar to this, but instead of styles being outside the shadow root, elements are being placed outside the shadow root. Doesn't look like Shadcn documents how to change this, I guess you need to provide your own solution on top of it.... But you say it's not possible? Doesn't Shadcn just download component code, can't you just change the portal container properly? The simplest thing would be to use react context to provide the element to add portals to. |
Beta Was this translation helpful? Give feedback.
-
Hello, I've been rewriting my extension using a bit more modern stack and I ended up using this framework and tailwind + shadcn components. I've almost instantly noticed that some of the styles work and some don't for shadcn. I've spent some time debugging it and found out why so I might as well share.
This seems to be an issue only in the content scripts. Some of the simple components like button or label work just fine, but dropdown doesn't.
Here is a reproduction repo which is some random starter with added components https://github.com/pact0/reproduction . When you look at the sidepanel entrypoint it uses the same dropdown as content script and in sidepanel the component is styled correctly in content script it is not.
The issue is shadcn uses radix undearneath which uses a concept called Portals to render things like dropdowns https://www.radix-ui.com/primitives/docs/utilities/portal in the documentation it says that it appends to the document.body by default and this is the culprit. When injecting the content script we create the shadow root which holds all the css we need. but the portaled components don't have access to them since the live in the root body.
Here is also a temp solution commented out which makes it work https://github.com/pact0/reproduction/blob/main/src/entrypoints/content/index.tsx just adding our styles to the original website, which is pretty bad, but works.
The ideal solution would be for shadcn to expose the portal custom container api somehow and allow us to change where these components get appended. I've seen a bunch of people ask about this issue and haven't seen anyone mention why this is happening. I hope this helps to somehow fix this
Beta Was this translation helpful? Give feedback.
All reactions