fix(react): conditionally self-accept fast-refresh HMR#10239
fix(react): conditionally self-accept fast-refresh HMR#10239patak-cat merged 8 commits intovitejs:mainfrom
Conversation
|
I pushed a commit here that implements the Todo
|
a94c657 to
37dbbd0
Compare
56f52e1 to
5d6b80e
Compare
But this is broken because Vite still treats this as self-accepting.
5d6b80e to
535aa4f
Compare
|
@aleclarson I've rebased this onto main now that the |
|
Thanks for the great job ! I think this was a blocking issue for a lot of us React users. There is a small issue with the CHANGELOG as this PR is not referenced there (even if it's int he commit history of release: v3.2.0-beta.1). |
|
Hi @abouroubi, this change was made to |
Description
Fixes #9869
Fixes #3301
Fixes #4298
Fixes #6885
Fixes #7396
Based on top of #10244
This makes a change to the HMR code that's injected by plugin-react to check the exports of a module, and determine whether it is safe to treat as a fast-refresh boundary. If it is a safe fast-refresh boundary, we will perform fast-refresh. If not, we now call
hot.invalidate()(relying on the changes in #10244) to propagate HMR up to parents. This is necessary because vite seesimport.meta.hot.accept()even if it's inside a conditional, and treats the module as self-accepting. So without callinghot.invalidate(), the parent will never know to fast-refresh.I've also added a test here for changing a react context file, and verified that it fails without the changes here, but passes with them.
Additional context
The other PR, #10244 should be reviewed first, since this one depends on it.
Thanks for help on this, @aleclarson!
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes vitejs/vite#123).