Skip to content
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

duplicate CSS <link> with renderBuiltUrl #14463

Closed
7 tasks done
lsdsjy opened this issue Sep 25, 2023 · 3 comments · Fixed by #16084
Closed
7 tasks done

duplicate CSS <link> with renderBuiltUrl #14463

lsdsjy opened this issue Sep 25, 2023 · 3 comments · Fixed by #16084
Labels
has workaround p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@lsdsjy
Copy link
Contributor

lsdsjy commented Sep 25, 2023

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

vite@4.4.9

Used Package Manager

npm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Sep 25, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@lsdsjy lsdsjy changed the title duplicate CSS <link> when using renderBuiltUrl duplicate CSS <link> with renderBuiltUrl Sep 25, 2023
@sapphi-red
Copy link
Member

This might be related to #13169.

@sapphi-red sapphi-red added the p3-minor-bug An edge case that only affects very specific usage (priority) label Nov 12, 2023
@sapphi-red
Copy link
Member

sapphi-red commented Feb 20, 2024

Yep, changing it to

return { runtime: `new URL('/' + ${JSON.stringify(filename)}, document.baseURI).href` };

works.

Closing as a duplicate of #13169 No it's not a dup 😅

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2024
@sapphi-red sapphi-red added duplicate This issue or pull request already exists p3-minor-bug An edge case that only affects very specific usage (priority) and removed p3-minor-bug An edge case that only affects very specific usage (priority) duplicate This issue or pull request already exists labels Feb 20, 2024
@sapphi-red sapphi-red reopened this Feb 20, 2024
@sapphi-red sapphi-red added has workaround p2-edge-case Bug, but has workaround or limited in scope (priority) and removed p3-minor-bug An edge case that only affects very specific usage (priority) labels Feb 20, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has workaround p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants