Skip to content

Order of <link> tags in HTML not preserved in prod build #8739

@silverwind

Description

@silverwind

Describe the bug

In index.html I dynamically load a static CSS file from publicDir:

<link rel="stylesheet" href="/src/App.css"/>
<link rel="stylesheet" href="/custom.css"/>

This works fine in dev mode and the links are ordered as defined, but in the prod build, vite renders the link tags in a different order, e.g. bundled style files seem to always append to end of <head> which breaks the order (and in turn the CSS precedence):

<link rel="stylesheet" href="/custom.css"/>
<script type="module" crossorigin src="/assets/index.84aa3832.js"></script>
<link rel="stylesheet" href="/assets/index.62f502b0.css">

Issue #6375 sounds similar but the root cause might be a different one as in this case, CSS is not loaded via JS, but directly from HTML.

Reproduction

https://github.com/silverwind/vite-style-order

System Info

not relevant

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: cssfeat: htmlinconsistencyInconsistency between dev & buildp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions