-
-
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
Baffling loss of styles in Markdown #11079
Comments
The issue is that when you call A workaround is to put some sort of HTML element in As for a fix, maybe we can skip the "render once" check when we render via |
Thanks; I'l try the workaround later. As I am sure aware, this whole thing is coming up because I am trying to do what I expected Like |
@bluwy your proposed workaround produces a malformed document: <!DOCTYPE html><style>div[data-astro-cid-yjwvcixp]{background:red}
</style><div></div> <html data-astro-cid-yjwvcixp> <head></head> <body data-astro-cid-yjwvcixp><div data-astro-cid-yjwvcixp> <p>Some content here</p> </div></body></html> The issue here is that I already have a As I understand it, the crux of my setup is
Any other ideas? Obviously in the MWE I could refactor this to move the |
Okay, so the best that I have come up with for a workaround is that
For example Good:
Also good:
Bad:
Because in that last case So with that knowledge, I have found the minimal refactor that I can make in my code, and I can live with it for now. However, in general this means that calling |
I think I know that a lot of people use it to check if a slot was passed, to render something different if not. I think this can also be implemented like this: <div class="content"><slot /></div>
<div class="fallback">Fallback here...</div>
<style>
.fallback {
display: none;
}
.content:empty + .fallback {
display: block;
}
</style> In any event, I can't think of a way to fix the issue you're experiencing here. |
Using client-side CSS to determine if a non-empty slot was passed is antithetical to static rendering, which is the whole point of using Astro. I understand why you would offer that as a solution (because it's better than nothing), but let's just acknowledge it for a gross hack that it is. Maybe I am missing something but the obvious way to fix the issue I am experiencing here is to make |
We can't know if a slot is going to result in no HTML unless we render it. We can't "fix" this in a way that won't just result in the same problem being described in this issue. |
It might be fixable by rethinking the slots APIs altogether though. It would be great to understand the use case more clearly. Is the use case purely about having fallbacks when the slot contents are empty? If that's the case we might be able to come up with something. Any solution probably means getting rid of conditional slot rendering (getting rid of |
My specific use case is 100% about trying to get a component with a slot to use the slot fallback content when the slot is passed in but its content is empty. I believe the specific situation I ran into this was along the lines of:
(but with a a bunch of additional intervening layers, so the obvious solution of moving the entire slot inside the ternary was not available) where IIRC |
Can you explain this for a Noob? I'm getting the same problem and your explanation is above my paygrade. |
@mpstaton sure. Do whatever it takes to rearrange your component tree so that your use of
Or to put yet differently: if |
How do I look to see if something is a descendant of the |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I promise I spent hours reducing this to a MWE and I think every part that is left in the example is needed for repro at this point:
test-md.md
using layoutTestA
and an Astro filetest-astro.astro
using the componentTestA
. The Markdown file is broken (as described below) while the Astro file works fineTestA
passes the default slot toTestB
as well as a<div/>
in slottest
TestB
passes an empty slothead
toTestC
TestB
passesRenderTest
toTestC
default slot, with thetest
slot ofRenderC
filled with thetest
slot ofTestB
TestC
puts thehead
slot into a<head>
RenderTest
callsslots.render('test')
And if you do all of that… then the HTML produced from the Markdown file has no styles:
but the HTML produced from the Astro file has styles as expected:
What's the expected result?
Styles should be present in output from both Markdown and Astro.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ttu457
Participation
The text was updated successfully, but these errors were encountered: