Skip to content
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

Under a feature flag, start setting up "Strict Mode" prefix for warnings. #13109

Closed
wants to merge 9 commits into from

Conversation

flarnie
Copy link
Contributor

@flarnie flarnie commented Jun 25, 2018

tldr: We want to add the "Strict Mode" prefix to all warnings which fire from within a 'strict mode' component tree, so that we can whitelist those warnings in our internal warning infrastructure.

This approach is not perfect, but we want to get something synced into Facebook asap to test before <StrictMode becomes widely used. This is an opportunity for us to clean up our current warning blacklist. Once we land this, we can filter for warnings with the Strict Mode prefix and whitelist those.

Once we figure out a strategy that we find helpful, we can start considering how to ease the pain of warnings landing in open source too.

What this does:

  • Adds ReactDebugCurrentFiber to shared so that we can access it inside of warning.
  • Update a couple of warning callsites as a proof of concept. Shows how we have to set up ReactDebugCurrentFiber if the warning is fired from the commit phase.
  • Update some tests for those warnings; one test we actually changed Baz to Baz, Foo. The original did fire a warning saying Baz, Foo but because partial matches pass, it was passing even though it only said Baz in the test expectation.

Concerns:

  • Adding 'Strict Mode' to warning strings is confusing, doesn't make sense, isn't helpful.
    --> But we need to try something, and it may not be so bad. Hard to say how people will generally perceive it.

  • Changing 'Strict Mode' behavior will cause problems for people who have adopted it.
    --> Except it's not widely adopted yet, so this is our change to make a little improvement.

  • It's a footgun to make reactWarning rely on the caller to have set up ReactDebugCurrentFiber to point to the right fiber.
    --> Probably, and we could move to passing in a flag, or just calling ReactDebugCurrentFiber.current.mode & StrictMode in the place where we construct the warning. But we may want to move to a different pattern of just using console.error instead of the warning/reactWarning wrappers, and this moves us in that direction.

  • This will mess with our warning logging.
    --> We can do something internally to transform the warnings, removing the 'Strict Mode' prefix before they are actually logged. Or we can just leave it, since 'Strict Mode' shouldn't affect too many callsites yet.

flarnie added 9 commits June 20, 2018 16:37
**what is the change?:**
TDD - we add a failing test and then make it pass.
This test will verify that any warning fired in strict mode gets the
prefix 'strict mode warning'.

**why make this change?:**
We want all warnings in strict mode to have this prefix so that we can
use it to configure our warning handler internally at Facebook, so that
no warnings will be supressed in 'strict mode'.

**test plan:**
Ran the test, watched it fail.

**issue:**
internal task T30481686
**what is the change?:**
- Moves 'ReactTypeOfMode' to the 'shared' directory
- Uses 'ReactTypeOfMode' and 'ReactDebugCurrentFiber' to detect when we
are in strict mode, allowing updating the warnings in the reconciler.

**why make this change?:**
We are in the process of prefixing all warnings with 'Strict Mode'.

**test plan:**
Run unit tests.

**issue:**
Internal task https://our.intern.facebook.com/intern/tasks/?t=30481686
**what is the change?:**
see title

**why make this change?:**
We are going to change warning behavior, better to have a feature flag
around this chnage in order to allow working on it incrementally and
also allow controlled release of the change.

**test plan:**
Will test this in a follow-up diff.

**issue:**
internal task https://our.intern.facebook.com/intern/tasks/?t=30481686
**what is the change?:**
See title

**why make this change?:**
We need this in many of our packages, and some were already requiring it
using the full path. Let's just move it to 'shared'.

**test plan:**
Ran build and tests.

**issue:**
Internal task T30481686
See PR for more full description of this.

**test plan:**
Updated unit tests, they are passing

**issue:**
Internal task T30481686
PropTypes = require('prop-types');
});

xit('should should prefix any warning with "Strict Mode Warning: "', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Intentionally ignored?

@pull-bot
Copy link

Details of bundled changes.

Comparing: 5b3d17a...dbbb4ef

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.6% +0.3% 626.73 KB 630.37 KB 146.5 KB 146.89 KB UMD_DEV
react-dom.development.js +0.6% +0.3% 622.86 KB 626.5 KB 145.33 KB 145.71 KB NODE_DEV
react-dom-server.browser.development.js +0.1% +0.1% 99.19 KB 99.26 KB 26.21 KB 26.24 KB UMD_DEV
react-dom-server.browser.development.js +0.1% +0.1% 95.32 KB 95.39 KB 25.28 KB 25.3 KB NODE_DEV
react-dom-server.node.development.js +0.1% +0.1% 97.24 KB 97.31 KB 25.81 KB 25.84 KB NODE_DEV
ReactDOM-dev.js +0.6% +0.7% 630.08 KB 634.02 KB 143.94 KB 144.96 KB FB_WWW_DEV
ReactDOMServer-dev.js +0.1% +0.1% 96.43 KB 96.51 KB 24.82 KB 24.84 KB FB_WWW_DEV

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +1.0% +0.6% 410.78 KB 414.74 KB 92.08 KB 92.64 KB UMD_DEV
react-art.development.js +1.2% +0.7% 342.76 KB 346.72 KB 74.94 KB 75.48 KB NODE_DEV
ReactART-dev.js +1.3% +1.6% 332.79 KB 337.04 KB 70.02 KB 71.13 KB FB_WWW_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +1.1% +0.7% 348.47 KB 352.36 KB 75.84 KB 76.37 KB UMD_DEV
react-test-renderer.development.js +1.1% +0.7% 344.59 KB 348.48 KB 74.86 KB 75.39 KB NODE_DEV
ReactTestRenderer-dev.js +1.2% +1.5% 347.82 KB 352.03 KB 73.6 KB 74.71 KB FB_WWW_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +1.2% +0.8% 333.28 KB 337.24 KB 71.4 KB 71.95 KB NODE_DEV
react-reconciler-persistent.development.js +1.2% +0.7% 331.89 KB 335.79 KB 70.84 KB 71.36 KB NODE_DEV

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.9% +0.5% 466.98 KB 471.24 KB 102.81 KB 103.36 KB RN_FB_DEV
ReactNativeRenderer-dev.js +0.9% +0.5% 466.69 KB 470.91 KB 102.75 KB 103.3 KB RN_OSS_DEV
ReactFabric-dev.js +0.9% +0.5% 457.24 KB 461.46 KB 100.4 KB 100.95 KB RN_FB_DEV
ReactFabric-dev.js +0.9% +0.5% 457.27 KB 461.49 KB 100.41 KB 100.96 KB RN_OSS_DEV

Generated by 🚫 dangerJS

@gaearon
Copy link
Collaborator

gaearon commented Aug 16, 2018

We did #13240 instead.

@gaearon gaearon closed this Aug 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants