-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix HMR failure with js error on load, take 2 #2531
Conversation
@@ -103,5 +111,12 @@ parcelRequire = (function (modules, cache, entry, globalName) { | |||
} | |||
|
|||
// Override the current require with this new one | |||
parcelRequire = newRequire; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems dangerous. Why are we overwriting the global variable here? Won't that already happen when the function returns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because returning doesn't work if an error is thrown and parcelRequire
is then undefined for subsequent HMR updates
parcel/packages/core/parcel-bundler/src/builtins/prelude.js
Lines 114 to 121 in 75a71be
parcelRequire = newRequire; | |
if(error){ | |
// throw error from earlier, _after updating parcelRequire_ | |
throw error; | |
} | |
return newRequire; |
And this overwrites a global variable as well:
parcelRequire = (function (modules, cache, entry, globalName) { |
↪️ Pull Request
See example.
I'm not sure if my changes have some side effect?
Might have a negative effect on scope-hoisting build sizes.
Fixes #879, previous attempt: #898
💻 Examples
On first load:
Removing the Error line doesn't hmr successfully.
✔️ PR Todo