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

Adjust Vite HMR implementation #502

Merged
merged 2 commits into from
Jan 21, 2025
Merged

Adjust Vite HMR implementation #502

merged 2 commits into from
Jan 21, 2025

Conversation

jods4
Copy link
Contributor

@jods4 jods4 commented Sep 6, 2024

server.reloadModule(mod) is documented as the way to push HMR here: https://vitejs.dev/guide/api-javascript.html#vitedevserver
I've used it in beforeWriteFiles and it worked for me.

I made updateRoutes non-async because:

  • You could await reloadModule but I don't think you should, and you didn't await the websocket in previous code either
  • Everywhere you call updateRoutes, you don't await it.
  • Interface ServerContext says it returns void not Promise.

@posva
Copy link
Owner

posva commented Sep 7, 2024

Thanks, I will have to give it a try. In the end there were other parts that were crucial during HMR like data loaders. I wish it was easier to write unit tests for HMR, it would allow me to make changes more confidently.

Copy link
Owner

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true that the method is not awaited, I returned the promise for the moment and adapted the Interface.
Thanks for this and sorry for the delay!

@posva posva merged commit 68bb979 into posva:main Jan 21, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants