Don’t bundle DebugTool in production #7189
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Most of this diff is indentation.
I am removing all
__DEV__
checks fromReactDebugTool
andReactDOMDebugTool
code. Instead, I am conditionally requiring them—in production,ReactInstrumentation.debugTool
andReactDOMInstrumentation.debugTool
would now benull
after this change.Why I am doing this:
.debugTool.*
are guarded by__DEV__
.__PROFILE__
build, we can change the same condition to include__PROFILE__
. There’s nothing here that would make it harder in the future.In the future, we might allow attaching devtools in production. Let’s do it when we actually have a use case for it. Right now it’s weird because we have these constraints that don’t actually end up getting used. This makes debug tool architecture more confusing to whoever who will be adding the
__PROFILE__
build.Even when we allow this, it is likely that the actual DebugTool would be external code. There is no need for it to live inside React. The default “broadcasting” DebugTools are good for development but I don’t see why they are useful in prod.
Let’s just keep it simple for now and let the code reflect our real usage. Debug tools are only called in development environment now.
This reduces build size a bit:
If we are concerned about stray
.debugTool.*
calls that would blow up in production, we can lint against using.debugTool.
outside a__DEV__
block. We don’t add new calls very often though so I’m not sure if it’s worth it.