fix: check for name of HotModuleReplacementPlugin to avoid RangeError #2146
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For Bugs and Features; did you add new tests?
Yes
Motivation / Use-Case
Fixes #87, a long-standing subtle bug which seems to have tripped up a lot of people historically.
Breaking Changes
No breaking changes.
Additional Info
See my comment on the issue: #87 (comment). The only way I can see this solution being a problem is if we're worried about configs that are using
--hot
and also have a plugin that isn'tHotModuleReplacementPlugin
but has the same name. In that case, we'd no longer inject the real HMR plugin. I'm not sure how likely this is and I seem to remember seeing other webpack plugins that check the name string rather than relying on the constructor reference (probably for this same reason).However, if we are concerned and if there's a property we can additionally check on the instances of the plugin, that would potentially be more robust. Ideally it'd be a property that's existing on the
HotModuleReplacementPlugin
for a while to make it as backward-compatible as possible.