You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm attempting to use the swr package in a Vite app, which is being built as UMD and embedded into another site.
I expect this to just work, but adding swr causes the CSS not to be included correctly in the UMD bundle. This means when the app is embedded the CSS isn't loaded and everything appears unstyled.
Since this is a problem in the UMD build, you can reproduce with:
npm run build
npm run serve
The default template CSS is still being imported, but is not activated so the page appears unstyled. If you comment out the SWR import then the CSS works correctly.
(index.html adjusted to load the UMD build instead of being the Vite entry point)
This seems to be because Vite is looking for the string execute: to insert the CSS after it. For UMD this is normally not found so the CSS is injected at the top, but since SWR happens to have this string in a comment in the middle of the library the CSS gets injected inside this function instead - meaning it isn't executed when the page loads.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
I'm attempting to use the
swr
package in a Vite app, which is being built as UMD and embedded into another site.I expect this to just work, but adding
swr
causes the CSS not to be included correctly in the UMD bundle. This means when the app is embedded the CSS isn't loaded and everything appears unstyled.Reproduction
https://stackblitz.com/edit/vitejs-vite-px4o6w
Steps to reproduce
Since this is a problem in the UMD build, you can reproduce with:
The default template CSS is still being imported, but is not activated so the page appears unstyled. If you comment out the SWR import then the CSS works correctly.
(
index.html
adjusted to load the UMD build instead of being the Vite entry point)This seems to be because Vite is looking for the string
execute:
to insert the CSS after it. For UMD this is normally not found so the CSS is injected at the top, but since SWR happens to have this string in a comment in the middle of the library the CSS gets injected inside this function instead - meaning it isn't executed when the page loads.System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: