-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Adds a dummy function to assist react devtools to look for minification #9661
Adds a dummy function to assist react devtools to look for minification #9661
Conversation
// Refer https://github.com/facebook/react-devtools/issues/694#issuecomment-300535376 | ||
var dummyMinificationTestFn = function() { | ||
if (__DEV__) { | ||
var anotherDummyNoop = function() {}; |
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.
How do we detect whether this code block was eliminated, judging by the source?
It can be tricky because it could be, for example, minified but not eliminated.
I think we should instead do something like return 42;
in __DEV__
block instead.
Then, on DevTools side, we can check both that:
- The function didn’t return anything (DEV mode check)
- The function doesn’t contain 42 literal (dead code elimination check)
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.
Fair point. Making the changes.
@@ -559,9 +559,19 @@ var ReactDOM = { | |||
}; | |||
|
|||
if (typeof injectInternals === 'function') { | |||
// A dummy function to check for minification during runtime | |||
// Refer https://github.com/facebook/react-devtools/issues/694#issuecomment-300535376 | |||
var dummyMinificationTestFn = function() { |
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.
Let's rename it to testMinification
.
We should also probably refactor this a bit and put the While you do that, could you please also remove conditional exports from |
I understand the concern, but I couldn't find any conditional exports in ReactFiberDevToolsHook |
Sorry I wasn’t clear. I mean stuff like this: let injectInternals = null;
let onCommitRoot = null;
let onCommitUnmount = null; Let's just keep them functions that are always properly exported, but change body of the functions depending on whether we found the hook or not. |
Also,
Or use object-assign. I vaguely remember some discussion about avoiding Object.assign inside React. |
Let's do whatever ReactDOM is doing for Fiber too.
Yes, or we could make those functions explicit positional arguments.
It's fine to use it, as we compile it to use a polyfill. |
dbd61db
to
cce7f65
Compare
@gaearon Yet to fix conditional exports. If these commits look good, I'll push in that fix as well. |
I would prefer that we get rid of |
I'm confused. Can you clarify what two functions you are talking about? Also pass them as positional params to what? |
@gaearon ^^ |
I mean instead of passing |
Oh. That will affect renderers trying to use |
Yes, please update them both. |
cce7f65
to
15a2daa
Compare
@gaearon Pushed the changes requested. Pending: conditional exports issue. |
injectInternals = function( | ||
findFiberByHostInstance: (instance: any) => Fiber, | ||
findHostInstanceByFiber: (component: Fiber) => any, | ||
bundleType: number, |
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.
I think bundleType
or version
can be calculated here instead of being passed as arguments.
15a2daa
to
a7cbb97
Compare
@gaearon Pushed the requested changes |
@gaearon |
Hey, sorry for the churn. There's many competing things happening at the same time and it gets a bit tricky to synchronize them. I guess let's go back to your previous approach with |
a7cbb97
to
0535f53
Compare
@gaearon I can understand :) I have pushed the changes. Please have a look. Again, conditional exports is yet to be dealt with. |
'the production build which skips development warnings and is faster. ' + | ||
'See https://fb.me/react-minification for more details.', | ||
); | ||
rendererID = rendererID = inject( |
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.
Unintentional double assignment?
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.
Sorry. Don't know how I missed that.
0535f53
to
4626242
Compare
@gaearon Good to go? |
4626242
to
dcea5ed
Compare
@gaearon Does this PR need more work? |
return 42; | ||
} | ||
}; | ||
warning( |
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.
injectInternals
only runs if DevTools exists.
Could you please move this out of the method?
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.
@gaearon Move testMinification
out of injectInternals
? Do we need it if there DevTools are not installed?
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.
We still should show the warning even if DevTools don't exist.
dcea5ed
to
65354d4
Compare
65354d4
to
70aa887
Compare
@gaearon Hi. Quite some time has passed by since this PR was raised. Is the idea behind it still valid? Should I resolve the conflicts and continue work? |
Sorry. I went on a holiday and later we’ve been in crunch mode fixing remaining issues in 16. We did something related in #10446 but then reverted in #10673 due to the discussion in #10640. I’m going to take another final look at this now and see if this approach still makes sense. We need some way to detect badly envified bundle but I’m not sure this is enough (or does the right thing) now. |
@gaearon No problem :) So if I understand right, calling So is checking for minification still a valid problem to solve? I'm refering to this comment here
Is Sebastian trying to say that we are tacking the problem at the wrong place? Or that the build process itself must ensure minification (else face byte code reversing issues) and beyond the build process there's nothing much we can do. |
Does it also mean there's no spec compliant way to retrieve the source string? |
Not exactly—we can call it but shouldn’t do so from inside of
I’m sorry I didn’t go ahead with your PR—unfortunately I didn’t realize the approach was flawed, and had to spend some time myself yesterday to figure out how to proceed. And I also didn’t realize your PR doesn’t solve the problem with flat bundles. If the user has bad dead code elimination they will still get a minified function inside of React. That’s why putting the check outside was important. |
Ah, It alright. Better luck next time I guess. Thanks nevertheless. Oh, and I was wondering, is it annoying as repo maintainers if contributors ping your on Twitter to get an update/feedback on a PR that's getting stale? Whats the right code of conduct in such a case? There are times when wished repo maintainers were available on IRC or something to give their opinion on an approach. Something more real time. |
You can always ping me in Twitter DM if you submitted a PR, just make it clear in first message :-) In general we try to be more responsive. It's just been very hard to keep track of things as we have the giant checklist related to the new implementation of everything. I think we'll pick up some steam after 16 and be able to sort through contributions more quickly. |
I can understand :) Great to hear this! |
Patch for react-devtools#694. Refer comment
cc @gaearon