Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Add bad dead code elimination detection for React 16 #888

Merged
merged 2 commits into from
Sep 14, 2017

Conversation

gaearon
Copy link
Contributor

@gaearon gaearon commented Sep 13, 2017

Counterpart to facebook/react#10702.
We need this because the hazard of shipping “two Reacts” is a new one due to flat bundles.

Our existing detection strategy doesn’t work here because it checks compiled code. But if you had bad DCE then you have two compiled versions, one of them dormant and never running but still present in your bundle.

So facebook/react#10702 sidesteps this problem by calling DevTools in the CommonJS entry point.

screen shot 2017-09-13 at 23 30 04

@@ -2,7 +2,7 @@
<style>
html, body {
font-size: 14px;
min-width: 430px;
min-width: 460px;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated but Chrome probably changed default fonts in popups because they started wrapping onto the next line a few versions ago. I made all popups 30px wider to make them look nice again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. 👍

@gaearon
Copy link
Contributor Author

gaearon commented Sep 13, 2017

Added the code to throw an error in setTimeout, just like we originally did in facebook/react#10446.

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming you tested this (because I did not) but it looks good. A bit bizarre though 😁

// (although this is not a problem since flat bundles).
if (findFiberCode.indexOf('getClosestInstanceFromNode') !== -1) {
return 'unminified';
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change means DevTools won't quite support 16 alpha/beta/RC? I guess that's okay though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be as good at detecting unminified alphas. Which seems okay. It won't report false positives though.

}
var toString = Function.prototype.toString;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why we do this (vs Function.prototype.toString.call)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason. It used to be used in more places but now it's not.

// This is a string embedded in the passed function under DEV-only
// condition. However the function executes only in PROD. Therefore,
// if we see it, dead code elimination did not work.
if (code.indexOf('^_^') > -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, should we put something slightly more descriptive? 😁
I guess this pretty unique and tiny which is nice. It's just so arbitrary.

Edit Looks like the corresponding change has already been merged to react so nevermind. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured I didn't want it to be long, but also didn't want it to be something that could accidentally appear in that function. Since then it would cause false positive.

@@ -2,7 +2,7 @@
<style>
html, body {
font-size: 14px;
min-width: 430px;
min-width: 460px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. 👍

@@ -2,7 +2,7 @@
<style>
html, body {
font-size: 14px;
min-width: 380px;
min-width: 410px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is intentionally a different size from the others (given it was already that way) but just pointing it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a different message that's less wide.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants