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

HMR not working when triggered from vite plugin #5783

Closed
1 task
UstymUkhman opened this issue Jan 6, 2023 · 4 comments · Fixed by #5849
Closed
1 task

HMR not working when triggered from vite plugin #5783

UstymUkhman opened this issue Jan 6, 2023 · 4 comments · Fixed by #5849
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) ecosystem: external External library doesn't work feat: hmr Related to HMR (scope)

Comments

@UstymUkhman
Copy link

What version of astro are you using?

1.9.0, 1.9.1

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm, yarn

What operating system are you using?

Windows

Describe the Bug

vite-plugin-glsl (for example) is using vite's server.restart method to trigger HMR when a shader file is changed and saved. When using this plugin with astro, after saving a file, dev server crashes unless the following setting is added to astro.config.mjs:

export default defineConfig({
  vite: {
    server: {
      port: 3000
    }
  }
});

Original bug report here;

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-ctfwyn?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.
@DaniloArantesF
Copy link

It also seems to work fine if you disable watch in the plugin's config. Not sure if it's standard behavior but my dev server also crashed silently and continued to update on file changes.

@UstymUkhman
Copy link
Author

UstymUkhman commented Jan 8, 2023

It also seems to work fine if you disable watch in the plugin's config.

@DaniloArantesF Yeah, good point, thanks for testing that. With watch: false option we don't rely on vite's server.restart and astro seems to handle file changes automatically. But I also don't know if that's a standard behavior.

...my dev server also crashed silently and continued to update on file changes.

Sorry, but I didn't get this. With plugin's watch: false option, it seems to be working just like with vite's server config, so in my tests I haven't see the dev server crashing, but it continued to fetch the latest version of the shader file just like if the plugin's watch option was set to true.

@bluwy bluwy added - P3: minor bug An edge case that only affects very specific usage (priority) feat: hmr Related to HMR (scope) ecosystem: external External library doesn't work labels Jan 10, 2023
@bluwy bluwy self-assigned this Jan 10, 2023
@bluwy
Copy link
Member

bluwy commented Jan 13, 2023

#5849 should fix this. Note that the restart would cause a weird blank page between page reloads as vite-plugin-glsl isn't properly handling the changes. It should use handleHotUpdate instead of configureServer to detect the changes. Otherwise, handleHotUpdate would fallback to a full reload, while the server is still starting up, causing the weird interim blank page.

@UstymUkhman
Copy link
Author

Thanks for the hint @bluwy ! I will take a look at handleHotUpdate on the plugin's side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) ecosystem: external External library doesn't work feat: hmr Related to HMR (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants