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

Vite plugin: get duplicated CSS using import './<file>.css' #8830

Open
stackia opened this issue Feb 21, 2024 · 2 comments
Open

Vite plugin: get duplicated CSS using import './<file>.css' #8830

stackia opened this issue Feb 21, 2024 · 2 comments

Comments

@stackia
Copy link

stackia commented Feb 21, 2024

Reproduction

When using vite dev server, import './<file>.css' will cause the css being injected twice.

StackBlitz: https://stackblitz.com/edit/remix-vite-bug-css-duplicate?file=package.json&initialPath=test

System Info

Not related.

Used Package Manager

pnpm

Expected Behavior

The referenced css should only be injected once.

Actual Behavior

image

@fire332
Copy link

fire332 commented Feb 22, 2024

This is intended.
See reply to my identical issue: #8759 (comment)

@pcattori Maybe it would be a good idea to add a comment to the remix injected style explaining the reason for the duplication to avoid future issues being filed.

@stackia
Copy link
Author

stackia commented Feb 28, 2024

From https://github.com/vitejs/vite/blob/7cfe80d0df7edfe861b8cc281303f20fc7633841/packages/vite/src/client/client.ts#L380 we can see vite/client will try to use existing style[data-vite-dev-id] if they are already rendered during SSR. Is it possible to change our injected <style> to match that format (<style data-vite-dev-id="<path>">) so vite/client can correctly handle our SSR styles?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants