Skip to content
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

MDX rendered by a layout does not emit CSS #7426

Closed
1 task done
kurtextrem opened this issue Jun 20, 2023 · 5 comments
Closed
1 task done

MDX rendered by a layout does not emit CSS #7426

kurtextrem opened this issue Jun 20, 2023 · 5 comments
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@kurtextrem
Copy link
Contributor

kurtextrem commented Jun 20, 2023

What version of astro are you using?

2.6.5

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

yarn (and pnpm)

What operating system are you using?

Windows

What browser are you using?

Chrome

Describe the Bug

When you use a layout to render a MDX page:

(Layout.astro)

---
const { post } = Astro.props;
const { Content } = await post.render();
---

<Content />

and the MDX page contains something that uses CSS modules, such as:

import Tweet from "../../components/Tweet.astro";
<Tweet id="1382838799420514317" />

where <Tweet> is an Astro component:

---
import { EmbeddedTweet } from "react-tweet";
import { getTweet } from "react-tweet/api";

interface Props {
    id: string;
}

const { id } = Astro.props;
const tweet = await getTweet(id);
---

<EmbeddedTweet tweet={tweet} />

It does not emit the CSS modules correctly, not in dev and not on build. See the attached codesandbox, where index.astro is broken - no CSS emitted, and then working.astro (/working), the CSS is emitted correctly, because I added the Tweet component to the WorkingLayout component. So only when you add the Tweet component to something non-MDX-related, it emits the CSS modules correctly.

Link to Minimal Reproducible Example

https://codesandbox.io/p/sandbox/lingering-microservice-cz8tnn?file=%2Fsrc%2Fpages%2Findex.mdx%3A1%2C1

Participation

  • I am willing to submit a pull request for this issue.
@natemoo-re natemoo-re added the - P3: minor bug An edge case that only affects very specific usage (priority) label Jun 21, 2023
@RobertDS07
Copy link

Hello @kurtextrem, how are you?

I've seen your codesandbox and analyzed the code. I found a possible solution by adding the directive client:load to the EmbeddedTweet component. The result is as expected.

Here is the link to my sandbox with the possible solution.

I'm not sure if it's expected to have to add this directive to a React library, but...

image

@kurtextrem
Copy link
Contributor Author

@RobertDS07 Thanks! I think this solution however makes Astros biggest benefit (not shipping JS) redundant...

@kurtextrem
Copy link
Contributor Author

kurtextrem commented Jun 27, 2023

Does anyone have a hint at where to start looking if I want to fix this bug?

(the work-around only partially fixes the issue: as you can see the unstyled tweet "flashes" while the assets are loading when adding client:load)

@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

This is an architectural limitation, I tried to provide an explanation as to why in a duplicate issue: #7761 (comment).

@natemoo-re
Copy link
Member

This seems to be a duplicate of #7761 so I'm going to track that there. Feel free to chime in on that conversation!

@natemoo-re natemoo-re closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

5 participants
@kurtextrem @natemoo-re @RobertDS07 @lilnasy and others