-
Notifications
You must be signed in to change notification settings - Fork 917
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
[plugin-react-refresh] Solve the problem with MobX observer() HOC #3015
[plugin-react-refresh] Solve the problem with MobX observer() HOC #3015
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/EXkeGVvpZExJGXdGYcovFGfWzbcL |
nice find |
LGTM! Appreciate the PR description as well, it was a fun read :) I can see why snapshot updating didn't work (you need to run |
Sorry, I had to revert: this caused a bad HMR injection in the basic
This is due to a commented out |
Okay, I got it. I'll push a fix version. |
Changes
It's all start with a bug of react-refresh. react-refresh doesn't work with MobX observer HOC. so @gaearon makes a fix on it. But the fix is not work with snowpack. After I checked all the babel plugins and transformers, I found out it's problem with plugin-react-refresh.
The story: facebook/react#20417 (comment)
The function
transformHtml()
in plugin-react-refresh insert the react-refresh code usingcontents.replace()
, so the$
will have meaning in the replaced content. The code ofnode_modules/react-refresh/cjs/react-refresh-runtime.development.js
has these lines:After replace, become:
That's the reason why @gaearon's fix not working. So I make a fix just like below:
Testing
For testing this issue, I create a sample project to test it. Here is the repo: https://github.com/yuhongda/repro-react-issues-20417
plugin.test.js.snap
. (I replace all the$typeof
to$$typeof
, so it will compatible with new version of react-refresh)Docs
bug fix only