inlined SVG is not updated unless the server is restarted #18963
Labels
feat: css
feat: hmr
p4-important
Violate documented behavior or significantly improves performance (priority)
Describe the bug
I'm implementing my own solution for avoiding FOUC during SSR using Environment API. I'm aware that Vite doesn't offer any recommended path to do this (#16515), I tried implementing various iterations of Hiroshi's plugin linked in that issue, but I wasn't able to make it work, and I didn't need much of that logic for my app anyway.
My project has a single CSS entry point, and what I've found is that if I import it with
?url
on SSR, insert the<link>
tag, and HMR will just work upon updating the CSS out of the box! I don't know why 😅However, I've now also found out that updating images imported by that CSS via
url()
aren't reflected in that CSS, even after a hard refresh. But I also see why — my SVG has already been inlined into the CSS, so the connection has been lost. I can work around this by forcing Vite not to inline during development viabuild.assetInlineLimit: () => false
, now after refreshing the page I get the update, but I'd also like HMR too if possible. However, thebuild.assetInlineLimit
thing doesn't feel like a workaround, but like a hack, I want to understand what's going on and how to do things the Vite way, whatever that might look like.Any advice for me? Am I going about this the wrong way? Is Vite behaving here as expected by inlining the linked asset during development in SSR with the
?url
import? This is something between a bug report and a question, I hope you don't mind me filing it here, it took me a long time to narrow it down.This is a development-only issue.
Reproduction
https://github.com/silvenon/repro/tree/vite-avoiding-fouc-hmr-css-imports (note the branch name when cloning)
Steps to reproduce
stroke
color, it won't get updated, even after a hard refreshAs you can guess, the repro (most likely) doesn't need React, I included it because it's easier for me to inline markup that way :smi
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: