-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix(unplugin): HMR support #69
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
2f28bd4
to
dc667f3
Compare
@@ -115,15 +115,7 @@ export const unpluginFactory: UnpluginFactory<PandaPluginOptions | undefined> = | |||
if (outfile !== ids.css.resolved) { | |||
getCtx().then((ctx) => fs.writeFile(outfile, ctx.toCss(ctx.panda.createSheet(), options))) | |||
} | |||
|
|||
const timestamp = Date.now() | |||
server.moduleGraph.invalidateModule(mod, new Set(), timestamp, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a similar line on 247 responding to changes in Vite. It seems like the invalidation here should be enough though, since this code will also get called when files change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's for a different code path of module invalidation and didn't want to change too much in scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's release it with this for now; we can always revisit that part later on if needed
I'll try on my end as well in a realworld project
btw we might want to add https://github.com/stackblitz-labs/pkg.pr.new if you guys want to contribute regularly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow. Yeah that would be awesome, didn't know that was a thing.
@astahmer cornflowerblue (imported via recipe and modified virtual:panda.css) is displayed on stackblitz launch now 🎊 |
Sending HMR updates manually with
server.moduleGraph
andserver.hot
seems to be the issue. By switching these toserver.reloadModule
updates appear to be loaded and sent properly to the browser. This works for both outfile and virtual module flavors.Relevant Vite PR: vitejs/vite#10333
I think we also need to debounce this a bit, maybe 100ms. When loading a large graph (like hundreds of files) I noticed HMR updates happening frequently (as expected). Need to play around with this in a separate PR, but this should fix HMR in general.
Fixes:
Current State
Proposed
Also, it looks like @anubra266 was also looking for a solution a while back.
patak-dev/vite-plugin-virtual#6
FYI looks like Vite does the

invalidateModule
behind the scenes when invoking this functionFixes #67