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

[RTR] Add usage warning behind flag #27903

Merged
merged 7 commits into from
Feb 23, 2024
Merged

Conversation

jackpope
Copy link
Contributor

@jackpope jackpope commented Jan 8, 2024

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

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Jan 8, 2024
@react-sizebot
Copy link

react-sizebot commented Jan 8, 2024

Comparing: 90a0ae1...113bf6f

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 176.87 kB 176.87 kB = 55.14 kB 55.14 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 178.97 kB 178.97 kB = 55.77 kB 55.77 kB
facebook-www/ReactDOM-prod.classic.js = 591.94 kB 591.94 kB = 104.47 kB 104.47 kB
facebook-www/ReactDOM-prod.modern.js = 575.23 kB 575.23 kB = 101.48 kB 101.48 kB
test_utils/ReactAllWarnings.js Deleted 67.04 kB 0.00 kB Deleted 16.43 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react/cjs/react-jsx-runtime.react-server.production.js = 5.25 kB 5.21 kB = 2.25 kB 2.25 kB
oss-experimental/react/cjs/react-jsx-runtime.production.js = 5.18 kB 5.14 kB = 2.23 kB 2.23 kB
oss-experimental/react/cjs/react-jsx-runtime.profiling.js = 5.18 kB 5.14 kB = 2.23 kB 2.23 kB
test_utils/ReactAllWarnings.js Deleted 67.04 kB 0.00 kB Deleted 16.43 kB 0.00 kB

Generated by 🚫 dangerJS against 113bf6f

@jackpope jackpope force-pushed the rtr-warning branch 2 times, most recently from e325338 to 05e79fb Compare January 8, 2024 22:27

const emptyObject = {};

export default class ReactShallowRendererWithWarning extends ReactShallowRenderer {
Copy link
Member

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.

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'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.',
Copy link
Member

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

Copy link
Contributor Author

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

if (__DEV__) {
if (
enableReactTestRendererWarning === true &&
global.__REACT_DEVTOOLS_GLOBAL_HOOK__ == null
Copy link
Member

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?

Copy link
Contributor Author

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.

@@ -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;
Copy link
Member

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.

@@ -51,6 +51,21 @@ function cleanNodeOrArray(node) {
}

describe('ReactTestRenderer', () => {
beforeEach(() => {
jest.resetModules();
ReactFeatureFlags.enableReactTestRendererWarning = false;
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

LGTM

@jackpope jackpope merged commit 66c8346 into facebook:main Feb 23, 2024
36 checks passed
@jackpope jackpope deleted the rtr-warning branch February 23, 2024 16:33
github-actions bot pushed a commit that referenced this pull request Feb 23, 2024
## 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)
jackpope added a commit that referenced this pull request Mar 26, 2024
## 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`
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
## 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`
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
## 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`
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants