-
-
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
Unhandled HMR updates should cause a page reload #2676
Conversation
I just noticed a major flaw: this breaks the "React HMR just works" feature, because re-executing all Javascript is fine with React. But it doesn't work with setInterval (#2606) or HTML custom elements (#2675). Possible solutions:
|
If this breaks react it will likely break a lot more libraries/frameworks. I think the reload flag would probably be our best bet in this case |
Closing as this change would break the other half of libraries (current React et al. work and setTimeout etc. don't). |
mmm, so really what we should do is do two passes: 1 to check if any module will accept, and another to actually re-execute the modules if so, or reload the page if not. |
= does any asset have a |
(global.parcelRequire.cache[asset.id] && | ||
(Boolean(global.parcelRequire.cache[asset.id].hot._acceptCallbacks.length) || | ||
Boolean(global.parcelRequire.cache[asset.id].hot._disposeCallbacks.length) | ||
) |
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 isn't quite enough. You need to traverse upward from the asset to the root asset and check if any of the parents accept the update as well as the asset itself. Basically, we need to split hmrAccept
up into two functions. One that traverses upward and checks if an update should be accepted, but without actually re-executing them. It can also keep track of all of the assets that need to be re-executed in a list. Then, if an update is accepted, go through the list we tracked earlier, and re-execute them.
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.
Done: extracted the actual execution into hmrAcceptRun
and kept track of them in assetsToAccept
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.
🎉
Hey, I wanted to comment here because when we updated our When we adopted Parcel initially, we did have issues with the HMR (as many people have) but we gradually resolved each of our issues and now HMR works quite well with our app. As a result, it was upsetting to discover that default HMR functionality completely broke. Usually, when an API changes in a library, I expect to see a large, bold "BREAKING CHANGE" notice in the Changelog, which would have given us context and an ability to properly handle the change. Ideally, this would have also been a major version bump as this functionality was introduced without being backwards-compatible. (I think, as a minor version bump, the ideal solution would have been to disable HMR with a flag, instead of changing the default.) I now know what to do, but I think the fix shouldn't have been hidden in a comment in another issue (#289 (comment)). I'll be looking into making a pull request to update your documentation and Changelog for people who might be running into similar issues. Thanks for your work on Parcel! |
#2509 still a problem in 2.0.0-alpha.3.2, so not sure this PR fixed that |
↪️ Pull Request
As mentioned in #289 (comment)
Closes #289, closes #2675, closes #2606, closes #2455, closes #2509
💻 Examples
Would case a full reload:
Would not:
🚨 Test instructions
See example
✔️ PR Todo