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

Dig deeper into Vite's HMR problems #1934

Open
sodic opened this issue Apr 3, 2024 · 0 comments
Open

Dig deeper into Vite's HMR problems #1934

sodic opened this issue Apr 3, 2024 · 0 comments
Labels
dx enhancement New feature or request research

Comments

@sodic
Copy link
Contributor

sodic commented Apr 3, 2024

We had some Vite HMR problems and fixed them by introducing the incremental option to the TS compiler. Context:

Here's a high-level overview of the relationship between Vite's HMR and our SDK (node_modules/wasp):

  • We want Vite to watch node_modules/wasp. If it didn't, we'd have to rerun wasp start on every significant change.
  • On the other hand, we don't want Vite to clear the web app's state and do a full site refresh unless necessary.

By default, TypeScript updates all output files regardless of whether they change or not. Also, Vite (again by default) decides whether to perform a refresh based on files' timestamps. Together, these two behaviors resulted in many redundant site refreshes.

Possible solutions:

  1. The best solution would be making Vite smarter when detecting changes (for example, by comparing file hashes instead of their timestamps).
  2. If that isn't possible, the second-best solution would be preventing TypeScript from updating unchaged output files, which can be done with the incremental compiler option.

Since redundant refreshes and output noise proved frustrating to our users, #1931 implemented the second option (incremental updates). This had a nice side effect of speeding up the SDK build.

We didn't have time to properly explore the first option (smart changes detection)

Therefore, we should

  • Explore the possibility of making Vite smarter about deciding when to refresh.
  • Figure out why this guy claims that it isn't possible to watch a locally linked package when it seems that it's not only possible but also unavoidable? Have we missed something?
@sodic sodic added enhancement New feature or request research dx labels Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx enhancement New feature or request research
Projects
None yet
Development

No branches or pull requests

1 participant