-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[@astrojs/lit] Slotted content is wrapped in <astro-slot>
elements which breaks native slot functionality
#5475
Comments
astro-slot
element that interferes with native slot elementsastro-slot
element that interferes with native slot element styling
astro-slot
element that interferes with native slot element stylingastro-slot
element that interferes with native slot elements
We are facing the same problem. Not only the We do have some components that have the next structure: <tab-bar>
<tab>Item 1<tab>
<tab>Item 2</tab>
<tab-bar> This pattern is quite regular with other components like It invalidates the use of the decorator Also, these components could grow dynamically, inserting more items into the container. Normally they would be inserted as children of the container element, but with the astro-slot component results into a strange structure difficult to parse <list>
<astro-slot>
<list-item>Old Item</list-item>
<list-item>Old Item</list-item>
</astro-slot>
<list-item>New Item</list-item>
<list-item>New Item</list-item>
</list> Here there is an example |
@hecspc Thank you for the additional explanation. You are right about the DOM APIs that aren't working as well. It seems like the bug is in the astro/packages/integrations/lit/server.js Line 63 in 299ae9b
|
I created a PR: #5500 To test it locally replace in
Result |
@ba55ie I am afraid that the element Actually making a quick search for I am afraid that this issue is a problem of the chosen astro structure and it is much deeper that just an integration problem. I hope that this can be solved but due to the lack of support or not enough traction of lit I don't think that this is going to get the enough attention to be solved. But until this is not solved the lit integration or any webcomponents can not be used in depth with a proper components set that are not just the simple ones from the examples. The irony is that |
https://lit.dev/docs/ssr/client-usage/ I am working on a large SSR project and all components seem to hydrate just fine. |
astro-slot
element that interferes with native slot elements<astro-slot>
elements which breaks native slot functionality
<astro-slot>
elements which breaks native slot functionality@astrojs/lit
] Slotted content is wrapped in <astro-slot>
elements which breaks native slot functionality
@astrojs/lit
] Slotted content is wrapped in <astro-slot>
elements which breaks native slot functionality<astro-slot>
elements which breaks native slot functionality
Close, but no cigar. 😢 I got it somewhat working, but it doesn't seem very solid. I also had to take into account the use case of nested Web Components which resulted in a messy regex. Hopefully somebody from |
Btw, this is the PR that introduced the |
I just took a look at the Stackblitz and I'm not sure what we can do from the Lit side here. If an element expects children of a certain type, or needs to directly style children, then inserting another element like Lit doesn't actually do anything with slots. They are entirely a native feature. Client-side and server-side we just render templates into a shadow root. The platform takes care of the rest. It seems like there needs to be some way for Astro to not add |
Looking at the linked PR, can the changes to the Lit renderer that inject cc @natemoo-re |
I think we probably shouldn't be adding the astro-slot elements here, which is used to emulate slots in non-wc frameworks. I would think that not doing so would fix this issue. |
Yup, the tricky part was restoring the original I've created a new PR. |
Fixed by #5776 |
@ba55ie can you submit this same PR against |
@matthewp Done. |
What version of
astro
are you using?1.16.11
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Windows, Linux
Describe the Bug
When using a client directive or the Class constructor for Lit Web Components an extraneous
astro-slot
element is created which interferes with styling of content within nativeslot
elements.When looking at the example
MyCard
elements, the first two don't get the correct css styling. Theh1
should behotpink
and the footer text should begray
.The added
<astro-slot><h1>...</h1></astro-slot>
element interferes with the styling, because the::slotted
selector only supports compound top-level selectors: https://developer.mozilla.org/en-US/docs/Web/CSS/::slottedThere are also some render issues. I also tried the
is:raw
directive, but that doesn't seem to make a difference.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-wqbjru?file=src/components/my-card.ts
Participation
The text was updated successfully, but these errors were encountered: