-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customisable target to append the styles tag #3940
Comments
I'm also attempting to introduce Svelte into a codebase that uses custom elements/shadow DOM extensively. I ran into the same issue with the Right now Svelte-constructed components that include the CSS in the JS aren't usable inside of a shadow root, but that use case feels like it should be supported somehow. |
The "custom element" tag might not be appropriate for this issue? Since this issue is a suggestion about how to change the vanilla JS component constructor interface to make it usable inside of external custom elements, as opposed to making any change to the Svelte compiler's CE output |
This will let me work around some shadow DOM unfortunateness: sveltejs/svelte#3940
Is this issue something the svelte-team would consider implementing? I would need the option to render my svelte-application inside a shadowDom and attach the styles inside the shadow root. If I could choose, where the styles should be applied, it would be a lot easier to maintain my project. PS: I don't have the option to write the CSS to a file and inject it into the shadowDom. I need to bundle everything into one JS file. |
hi any updates on this? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
We are aiming to use Svelte with compilation to custom-elements in our company. However it feels like custom elements compilation is rather limited at the moment - there are multiple issues, including:
My proposal is to deliver a pragmatic fix to the third issue, so that people can successfully trap Svelte apps in web-components with shadow-dom with little effort and reliance on the black-box compiler.
I pretty much had only one weekend to try and read into the compiler code and solve the issue, to secure the future use of Svelte in our company. This is what can be done:
We need to change the definiton of generated function named "add_css", adding an argument, named
customStyleTag
, and using it before@_document.head
:Also, the generated definition of the component class needs to be altered:
customStyleTag
property somewhere (I chose the parent component class, due to not finding a better place in the limited time I had).customStyleTag
property as an argument to the generatedadd_css
function call.This will allow to specify the root Svelte component in the following manner:
and have the styles trapped in the shadow-dom properly.
Not being able to use Svelte app as a custom element is pretty much a deal breaker for our company. We have considered all of the documented approaches but each one of them lacks functionality to be considered seriously.
PS. Yes, I feel that this might be a hacky way of doing things, especially considering the fact that Im not familiar with the codebase, conventions, etc. However this is a deal breaker, and we really want to use Svelte in production and give it a warm welcome to our codebase.
Thanks for reading through :)
The text was updated successfully, but these errors were encountered: