-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Parcel 2: Bundled CSS is imported at the top of <head> instead of being last #4882
Comments
What do the input HTML/JS file(s) look like? |
Actually, I think it's just having the index.html: <html>
<head>
<link rel="stylesheet" href="https://www.example.com/some.css" />
</head>
<body>
<h1>Hey</h1>
<script src="index.js"></script>
</body>
</html> index.js import "/styles/test.css"; test.css body {
background: red;
} Output:
Not sure why sometimes the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Can you confirm that the example above reproduces the issue on your machine? |
Yes Your example <html>
<head>
<link rel="stylesheet" href="https://www.example.com/some.css" />
</head>
<body>
<h1>Hey</h1>
<script src="index.js"></script>
</body>
</html> shoud behave like <html>
<head>
<link rel="stylesheet" href="https://www.example.com/some.css" />
<script src="index.js"></script>
</head>
<body>
<h1>Hey</h1>
</body>
</html> which already correctly inserts the link after the existing one: <html>
<head>
<link rel="stylesheet" href="https://www.example.com/some.css" />
<link rel="stylesheet" href="/index.2ccae8b1.css" />
<script src="/index.b1eda6b3.js"></script>
</head>
<body>
<h1>Hey</h1>
</body>
</html> |
Any progress on this? The order of CSS imports is really important. |
I have the same issue and I think I found the reason for this to happen.
The function By changing the line to fallback to the last position should fix the issue, something like: return doctypeIndex ? doctypeIndex + 1 : content.length; What do you think? I can open a PR but I would need help to figure out if this can have a negative impact somewhere else. |
Are you saying that I can somehow force the bundled CSS to be added after a specific tag (before the fix is implemented)? |
It's not ideal but, right now if you add a The result will be something like: <head>
<link rel="stylesheet" href="https://www.example.com/some.css" />
<style>html,body {background: #e9eaed;}</style>
<link rel="stylesheet" href="/bundle.22506e2f.css"> <!-- HERE -->
<span></span>
</head> Edit.: Not just span, but any tag other than |
So adding an empty |
Absolutely! I didn't notice that the I'll try to open a PR in the next few days, still haven't got the time just yet. |
A PR would be great! Here are the related test cases we currently have. I remember adding the last two tests listed here when I added the
|
This avoids issues with Parcel as Parcel places style sheet links always at the top of the head section. See parcel-bundler/parcel#4882 Fixes #11
🐛 bug report
If you add a
<style>
tag in the head, the CSS bundle will be imported before everything instead of being added as a last child in<head>
.Previous discussion: #4820
🤔 Expected Behavior
Bundled CSS is always added as last child in
<head>
.😯 Current Behavior
Bundled CSS is imported as first child.
The bundled CSS is no longer at the end of the
<head>
tag, sosome.css
would overwrite it.💁 Possible Solution
Not sure why this happens, maybe it tries to add the bundle before the inline styles, which might be ok, but it shouldn't add it before all the other nodes in head.
🔦 Context
I can't overwrite library CSS as the bundled stylesheet is imported before those extenral CSS files.
💻 Code Sample
🌍 Your Environment
The text was updated successfully, but these errors were encountered: