-
-
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
Astro reverses the order of <style> tags in a page/component #12264
Comments
Is there a particular reason why you require two or more |
I'm migrating a project that's already set up this way. Of course, I can go through and merge the <style> tags together, but in the meantime until I do that work, Astro is breaking it. It's valid code to have multiple <style> tags in a document, so surely Astro should handle this correctly? I'm not familiar with Astro's internals, but since it's somehow generating them backwards, I'm guessing the order just needs to be reversed somewhere. |
By the way, we require a valid reproduction. I can't access to the one you provided. |
Hello @JaneSmith. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
Apologies. The repro link was set to private for some reason — I'm not sure how, as it was working when I opened the issue. I've changed the permissions, so it should be accessible now. |
Did some digging with @TheOtterlord, this was introduced with compiler#525 in Astro v1.4.0, although technically this was introduced even earlier in 0.21.0-next.2, where compiler#130 reversed the order of all rendered CSS/scripts/hydrated components. So a regression from two years ago for a change from 3 years ago. This also affects the order of scripts, even in the latest version of Astro. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
N/A
Describe the Bug
If a page or component contains multiple <style> tags, Astro seems to reverse the order of them.
For example, a page with the following code...
...ends up producing the following output in the dev server...
...and the following final output from the build command...
I defined a red style followed by a yellow style, but instead I got the yellow style followed by the red style. This is reversed.
Changing the order of the style tags has significant effects on the appearance of the page in the browser, as normally styles that come later in the document will override styles that come earlier in the document.
I don't see any reason why Astro would be doing this intentionally, and the behaviour is not documented anywhere as far as I can tell, so I believe this is a bug. It had me quite confused for a while as to why my styles weren't working, until I looked at the generated output and realised Astro was randomly changing this...
What's the expected result?
I expect the <style> tags (or lifted styles) to stay in the same order I put them in.
Link to Minimal Reproducible Example
https://codesandbox.io/p/devbox/amazing-meitner-6c8kkc?file=%2Fsrc%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: