-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
[RTR] Add usage warning behind flag #27903
Conversation
Comparing: 90a0ae1...113bf6f Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
e325338
to
05e79fb
Compare
|
||
const emptyObject = {}; | ||
|
||
export default class ReactShallowRendererWithWarning extends ReactShallowRenderer { |
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.
What do you think about hoisting the feature flag check to the module level so the warning class is only included in builds where the warning is on? GCC will strip that class in builds that don't use it, and this will prevent the additional stack frame in errors for React Native.
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'm simplifying this PR by dropping the changes to the shallow entrypoint. It looks like we don't have shallow configured in rollup anymore and we may want to consider dropping it altogether as its been a separate package re-exported here for a while. Will follow up on this
if (enableReactTestRendererWarning === true) { | ||
console.warn( | ||
"React's Shallow Renderer export will be removed in a future release. " + | ||
'Please use @testing-library/react instead.', |
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.
IMO we should provide a link here, that explains the deprecation better and we can keep the recommendations up to date on that page. Here's an example of where we've done this in the past: https://legacy.reactjs.org/warnings/legacy-factories.html
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.
Updated with link to warning page
afedfc5
to
e24023b
Compare
if (__DEV__) { | ||
if ( | ||
enableReactTestRendererWarning === true && | ||
global.__REACT_DEVTOOLS_GLOBAL_HOOK__ == null |
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.
Why are we checking this?
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.
Dev tools rely on RTR a bunch within their testing. This avoid the warning there which breaks tests in CI. I can remove for now since this PR isn't turning on the flag yet.
packages/shared/ReactFeatureFlags.js
Outdated
@@ -197,6 +197,9 @@ export const enableUnifiedSyncLane = true; | |||
// Adds an opt-in to time slicing for updates that aren't wrapped in startTransition. | |||
export const allowConcurrentByDefault = false; | |||
|
|||
// Warn on any usage of ReactTestRenderer | |||
export const enableReactTestRendererWarning = false; |
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.
This can go in the Next Major section below.
97d4ba2
to
113bf6f
Compare
@@ -51,6 +51,21 @@ function cleanNodeOrArray(node) { | |||
} | |||
|
|||
describe('ReactTestRenderer', () => { | |||
beforeEach(() => { | |||
jest.resetModules(); | |||
ReactFeatureFlags.enableReactTestRendererWarning = false; |
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.
Can we use the @GATE pragma?
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.
In the next PR we silence the warning to allow us to turn the flag on before all the React test cleanup is finished. So for now we don't necessarily expect a pass/fail on each side of the flag. Can probably update in the future or we'll see if we can remove the flag altogether
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.
LGTM
## Summary Moving towards deprecation of ReactTestRenderer. Log a warning on each render so we can remove the exports in a future major version. We can enable this flag in web RTR without disrupting RN tests by flipping the flag in `packages/shared/forks/ReactFeatureFlags.test-renderer.js` ## How did you test this change? `yarn test packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js` DiffTrain build for [66c8346](66c8346)
### React upstream changes - facebook/react#28438 - facebook/react#28436 - facebook/react#25954 - facebook/react#28434 - facebook/react#28433 - facebook/react#28432 - facebook/react#28415 - facebook/react#27903 - facebook/react#28430 - facebook/react#28424 - facebook/react#28400 - facebook/react#28422 - facebook/react#28423 - facebook/react#28412 - facebook/react#28418 - facebook/react#28421 - facebook/react#28417 - facebook/react#28399 - facebook/react#28408 - facebook/react#28350 - facebook/react#28387 - facebook/react#28403 - facebook/react#28384 - facebook/react#28409 - facebook/react#28398 - facebook/react#28405 - facebook/react#28328 - facebook/react#28402 - facebook/react#28386 - facebook/react#28388 - facebook/react#28379 - facebook/react#28383 - facebook/react#28390 - facebook/react#28389 - facebook/react#28382 - facebook/react#28348 Closes NEXT-2600
## Summary Based on - #27903 This PR - Silence warning in React tests - Turn on flag We want to finish cleaning up internal RTR usage, but let's prioritize the deprecation process. We do this by silencing the internal warning for now. ## How did you test this change? `yarn build` `yarn test ReactHooksInspectionIntegration -b`
## Summary Moving towards deprecation of ReactTestRenderer. Log a warning on each render so we can remove the exports in a future major version. We can enable this flag in web RTR without disrupting RN tests by flipping the flag in `packages/shared/forks/ReactFeatureFlags.test-renderer.js` ## How did you test this change? `yarn test packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js`
## Summary Based on - facebook#27903 This PR - Silence warning in React tests - Turn on flag We want to finish cleaning up internal RTR usage, but let's prioritize the deprecation process. We do this by silencing the internal warning for now. ## How did you test this change? `yarn build` `yarn test ReactHooksInspectionIntegration -b`
## Summary Moving towards deprecation of ReactTestRenderer. Log a warning on each render so we can remove the exports in a future major version. We can enable this flag in web RTR without disrupting RN tests by flipping the flag in `packages/shared/forks/ReactFeatureFlags.test-renderer.js` ## How did you test this change? `yarn test packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js` DiffTrain build for commit 66c8346.
Summary
Moving towards deprecation of ReactTestRenderer. Log a warning on each render so we can remove the exports in a future major version.
We can enable this flag in web RTR without disrupting RN tests by flipping the flag in
packages/shared/forks/ReactFeatureFlags.test-renderer.js
How did you test this change?
yarn test packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js