-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 Layout css applied after component css on build #11040
Comments
As a workaround for the layer declaration issue, I've added the following to the <style is:inline>
@layer reset, component;
</style> |
Thanks, are layers important for this bug report? Could the same sort of issue not exist without the use of layers? |
Thanks for the quick reply! Layers are not required for the bug, just used to illustrate the issue. Per the astro docs, it's recommended that layout components are imported first so that component styles win out if there's conflicting styles with the same specificity.
|
I wonder if it's because we import the layout this way, which messes with the CSS ordering:
|
@ascorbic I assigned this to you but you might want to wait until @bholmesdev is back and talk to him about it as I think he has context for why we dynamically import the Layout. Ideally we could stop doing that, and then the import could be at the top. |
@matthewp Thanks for tagging me on this! Had to refresh myself with the the PR linked in the code comment. TLDR: an async import prevents dev server slowdowns for layouts that make recursive globs for the page. Using async imports to preserve the Vite cache isn't documented behavior, so it could have changed in the past 2 years. Unfortunately, this isn't something we have in our testing suite. The linked PR was manually tested against Bryce Wray's blog that displayed the issue. To repro and test, I would:
If there's still a slowdown when the import is made synchronous, I would keep it where it is. |
I'll re-assign this to myself as we've got reports that this blocks the upgrade to |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When using the mdx integration, if you specify a layout in the frontmatter, the CSS from that layout will be included after any imported component css when built.
In the linked stackoverflow,
pages/index.mdx
imports a component (Demo.astro
) which has some component styles, and has a layout (RootLayout.astro
) which includes some global styles that specify the layer order with the@layer
directive.Here's the relevant css:
The compiled css ends up looking like this (whitespace added for readability):
Because the component layer is declared before the reset layer, the reset layer is taking precedence.
What's the expected result?
I'd expect the styles from the layout to be included before the styles from any imported components:
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ceeysf?file=src%2Fcomponents%2FDemo.astro
Participation
The text was updated successfully, but these errors were encountered: