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
[Fresh] Clone a custom hook node before use #16019
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
No significant bundle size changes to report. Generated by 🚫 dangerJS |
I think deep clone is necessary for related cases. I can repro today or tomorrow if you want. I haven’t tried it yet, but I would try 1) “import *” and 2) importing a name foo and doing foo.useHook. |
It would be nice to get a confirmed repro case that fails with Babel 7, even in a fork. Then we can keep the test, and it will become useful once we update to Babel 7. Which we should do anyway. |
Ok - test would be green today, and would be green in the future, as long as the problem is "fixed". But, at least, it would prevent regression. @dgreensp - It does not matter how you've imported "hook", only |
What if callee is something like |
Does not matter - only "top level" transformation matters here(and for this case), le transformation from Anyway - if the goal is to provide more safe out of the box solution - let's use deep clone. |
Yeah, feels a bit safer. Let's use the deep one. |
My intuition was that foo.bar.baz() is actually (((foo).bar).baz)(), so the callee is foo.bar.baz and the imported identifier is foo, a descendent node. I tried to repro it real quick and couldn’t, but it sounds like you’re going to go with deep, so sounds good to me. |
Thanks! |
😅 someone got that theoretical problem, which might require |
This is a small patch to react-refresh babel plugin to fix a problem we found in react-hot-loader.
In short - refresh babel plugin is using the "original" babel node to put a custom hook into
signature
, andcommon-js
babel plugin has a logical condition not to transform any node twice. As a result - custom hook reference would not be transformed. @dgreensp did an amazing job finding the root cause.Solution - just
clone
node before the use. Look like there is no need for deep clone in this case.Keep in mind - no tests were added. Unfortunately, this bug is not reproducible with babel 6, and only babel 7 is affected. To be more concrete - I've added tests, but as long as they are not testing anything - they are passing initially - I've removed them.