-
-
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
context api not working with custom-elements #8987
Comments
Context works for regular Svelte components used within a custom elements now (this is why the mentioned issue was closed), but it does not work across custom elements. There's no reliably way to make this happen, ultimately |
@dummdidumm well i if im correct parent component gets mounted before the child ones when using slots right so this way there could be a message bus of some kind between them, not sure how vue for example did this is vue3 they also did something with there inject provide i think https://vuejs.org/guide/extras/web-components.html#building-custom-elements-with-vue im also on discord posted this also here https://discord.com/channels/457912077277855764/1130569409388367932 if you want a more active conversation thing is that its then not documented as good |
This should help everyone who has special needs and use cases around custom elements. Since Svelte components are wrapped and only run on connectedCallback, it makes sense to expose the custom element class for modification before that. - fixes #8954 / closes #8955 - use extend to attach the function manually and save possible values to a prop - closes #8473 / closes #4168 - use extend to set the proper static attribute and then call attachInternals in the constructor - closes #8472 - use extend to attach anything custom you need - closes #3091 - pass `this` to a prop of your choice and use it inside your component - add some doc for #8987
i saw your pr, @dummdidumm looks nice the way you can extend now. |
I was able to cleanly implement context for Svelte-based custom elements using svelte-retag. I found that while custom elements can be rendered in a seemingly unpredictable order (at least from the perspective of Svelte and @pascalvos if you’d like, please give it a shot and let me know if you encounter any issues. 😊 More Technically: The reason I think this is able to be solved is because @dummdidumm do you have more details on your point about reliability? I want to make sure that I take care of any other issues beyond that (rendering/initialization order) I may not have thought of, since I’ll be using it with custom elements pretty heavily myself. Importantly, this approach isn’t prone to the order upon which the |
p.s. Just for fun: Another interesting caveat I found was the catch-22 of being able to support lit-style lowercased attributes (i.e. translating element Originally, I just took the naive approach of constructing the component and then inspecting its The simple solution to that however is just to use a |
Describe the bug
i tried to implement https://svelte.dev/docs/svelte#getcontext with custom elements after the svelte 4 release.
i thought it was fixed in #3422 and #8457 but it looks like its still doesnt work.
if i can help in any way let me know, because this currently blocks my implementation
if this cant be fixed it might be an idea to update https://svelte.dev/docs/custom-elements-api#caveats-and-limitations until it is fixed
Reproduction
reproduction of the actual code using svelte 4.0.5 https://stackblitz.com/edit/vitejs-vite-gk4rsr
in uc-button-group.svelte i commented out these lines
they use the svelte component directly and work without any problem :)
i made the reproduction on stackblitz because some issues with the repl i already reported in discord :)
Logs
No response
System Info
Severity
blocking all usage of svelte
The text was updated successfully, but these errors were encountered: