[9.x] Fix ordering of stylesheets when using @vite - #43962
Conversation
In order to allow CSS overrides from within the application's stylesheet, the application's stylesheet has to be included *after* any vendor stylesheet.
|
@jul13579 thank you for the PR! Are you able please provide a minimal reproduction case for this? I was unable to replicate this to verify the issue. Thank you! |
Hi @timacdonald! Thank you for your quick response. I have now set-up the bug-report repo here, where I consolidated the example into this single commit. I used the same setup that I used in my other project, hence there might even be a more minimal example. When using the code from above referenced commit, do the following to reproduce the issue:
Now if you navigate to <link rel="stylesheet" href="http://127.0.0.1:8000/build/assets/app.8e438c19.css">
<link rel="stylesheet" href="http://127.0.0.1:8000/build/assets/vendor.dc6e3714.css">When you manually reorder those elements by dragging and dropping the I hope this helps and actually is what you wanted me to do 😅 |
timacdonald
left a comment
There was a problem hiding this comment.
I've verified this issue and the fix. Additionally, this created parity between the dev server and the build.
Unfortunately this bug fix is also a potentially breaking change, but I do feel it is worthwhile making the change now as a bugfix.
As the CSS tags were in the wrong order, vendor CSS may be overriding userland CSS.
Not a breaking change if this was noticed and the userland CSS precedence was forced, e.g. ! important.
Breaking change if this was not noticed and the vendor CSS is still taking precedence. So although it is breaking, it is also really what is expected i.e. my CSS has higher precedence than vendor CSS.
Thank you very much @jul13579 for the PR and reproduction!
First up: Thank you all so much for this awesome framework (and the great documentation). I'm using it for many years now and always enjoy working with it!
When I started a new project recently I however came across a problem: My stylesheets end up in the wrong order in the rendered HTML when using
@vite. This prevented any CSS overrides from within my application's stylesheet to actually work.This is the current order of the stylesheets:
when it should IMHO actually be the other way around.
This PR fixes this issue, although please forgive the very "quick-fix" nature of the PR. I'm not aware if my changes could break things elsewhere or if this actually touches intended behaviour.
For anyone coming across this
For the time being, I solved this issue in my project by introducing a custom blade directive and extending from
\Illuminate\Foundation\Vite. This allowed me to prevent any changes tovendorcode while still being able to have my stylesheets rendered in the right order.Afterwards just use
@vite_custom(...)instead of@vite(...)in your blade templates 😉