Skip to content

duplicate CSS <link> with renderBuiltUrl #14463

@lsdsjy

Description

@lsdsjy

Describe the bug

Specify renderBuiltUrl like this:

    renderBuiltUrl(filename, { hostType }) {
      if (hostType === 'js') {
        return { runtime: `'/' + ${JSON.stringify(filename)}` };
      }
    },

then dynamic imports can lead to CSS links duplicated. For example, in the reproduction:
image

If the prefix is just '/' then I can simply use base: '/'; but the real situation for me is more complicated, where the prefix is not determined at build time and sometimes it is '/', so 'base' is not an option here.

Reproduction

https://stackblitz.com/edit/vitejs-vite-cssjgy?file=vite.config.js

Steps to reproduce

npm run build && npm run preivew

System Info

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    has workaroundp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions