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

How does browser swap in the new module? #24

Open
marialovesbeans opened this issue Mar 26, 2021 · 1 comment
Open

How does browser swap in the new module? #24

marialovesbeans opened this issue Mar 26, 2021 · 1 comment

Comments

@marialovesbeans
Copy link

marialovesbeans commented Mar 26, 2021

Hey guys, does anyone understand how ES Module's HMR works under-the-hood (for example in Vite or React Fast Refresh)? i.e. How is it able to swap out a modified module at runtime?

Usually, every time you change a module, browser will refetch that module via HTTP.

But after that, how does the browser replace the old module, and have the new code take into effect?

The only thing I found is https://itnext.io/hot-reloading-native-es2015-modules-dc54cd8cca01, is this the solution we're taking?

@lxsmnsyc
Copy link

https://github.com/snowpackjs/esm-hmr/blob/152fffe555e9281822553b495edbc95ccb6a41b2/src/client.ts#L131-L137

It uses module versioning and dynamic imports to "reload" modules without deleting the module cache. The loaded content is then passed to import.meta.hot.accept for consumption.

Also, commenting this for my own future reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants