-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
add invalidate to HMR API #10714
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
add invalidate to HMR API #10714
Conversation
|
For maintainers only:
|
add invalidate to HMR API
|
@pmmmwh @gaearon Do this help for react-fast-refresh in webpack? @evilebottnawi for style-loader? |
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
Is there any way to reliably capture the list of exports without generating code? Whether CJS or ESM. |
import * as SELF from "./self.js";
Object.keys(SELF)In loose ESM and CJS you could also use Or In webpack 5 there is We could consider adding a Note that these variants above have different properties regarding marking all exports as used and enumerating mangled export names.
Note that export name mangling only happen in production mode. |
|
I've created an issue to document this in webpack/webpack.js.org. |
refactor HMR javascript part to reduce duplication
What kind of change does this PR introduce?
feature
Did you add tests for your changes?
yes
Does this PR introduce a breaking change?
yes
What needs to be documented once your changes are merged?
module.hot.invalidate()Calling this method will invalidate the current module which disposes and recreates this module when the HMR update is applied. This bubbles like a normal update of this module.
invalidatecan't be self-accepted by this module.When called during the
idlestate, a new HMR update will be created containing this module. HMR will enter thereadystate.When called during the
readyorpreparestate, this module will be added to the current HMR update.When called during the
checkstate, the module will be added to the update when an update is available. If no update is available it will create a new update. HMR will enter thereadystate.When called during the
disposeorapplystate, HMR will automatically do an additionaldisposeandapplycycle after the current cycle has finished.Use cases
Conditional accepting
A module can accept a dependency, but can call invalidate when the change of the dependency is not handle-able:
Conditional self accept
A module can self-accept itself, but can invalidate itself when the change is not handle-able:
Triggering custom HMR updates
Notes
When
invalidateis called, thedisposehandler will eventually called and fillmodule.hot.data. If nodisposehandler is registered an empty object is still provided formodule.hot.data.Make sure to not get catched in a
invalidateloop, by callinginvalidateagain and again. This will result in stack overflow and HMR entering thefailstate.