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

Add stable React.act export #28160

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions fixtures/dom/src/__tests__/nested-act-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('unmocked scheduler', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
DOMAct = React.unstable_act;
DOMAct = React.act;
TestRenderer = require('react-test-renderer');
TestAct = TestRenderer.act;
});
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('mocked scheduler', () => {
require.requireActual('scheduler/unstable_mock')
);
React = require('react');
DOMAct = React.unstable_act;
DOMAct = React.act;
TestRenderer = require('react-test-renderer');
TestAct = TestRenderer.act;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ describe('Store component filters', () => {
let utils;

const act = async (callback: Function) => {
if (React.unstable_act != null) {
if (React.act != null) {
await React.act(callback);
} else if (React.unstable_act != null) {
await React.unstable_act(callback);
} else {
callback();
Expand Down
4 changes: 3 additions & 1 deletion packages/react-devtools-shared/src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export function act(
const {act: actTestRenderer} = require('react-test-renderer');
// Use `require('react-dom/test-utils').act` as a fallback for React 17, which can be used in integration tests for React DevTools.
const actDOM =
require('react').unstable_act || require('react-dom/test-utils').act;
require('react').act ||
require('react').unstable_act ||
require('react-dom/test-utils').act;

actDOM(() => {
actTestRenderer(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ReactDOMServerHydration', () => {
React = require('react');
ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
act = React.unstable_act;
act = React.act;

console.error = jest.fn();
container = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ beforeEach(() => {
yields = [];
React = require('react');
ReactDOMClient = require('react-dom/client');
act = React.unstable_act;
act = React.act;
container = document.createElement('div');
document.body.appendChild(container);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const getFiberCurrentPropsFromNode = EventInternals[2];
const enqueueStateRestore = EventInternals[3];
const restoreStateIfNeeded = EventInternals[4];

const act = React.unstable_act;
// TODO: Add a warning if this API is accessed with advice to switch to
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we want to remove react-dom/test-utils, do we really need a warning since that won't appear in any stable release anyway?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the current plan is to remove everything except act from the test-utils for a single release, then remove in 20.

// importing directly from the React package instead.
const act = React.act;

function Event(suffix) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('act warnings', () => {
React = require('react');
Scheduler = require('scheduler');
ReactNoop = require('react-noop-renderer');
act = React.unstable_act;
act = React.act;
useState = React.useState;
Suspense = React.Suspense;
startTransition = React.startTransition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('ReactFiberHostContext', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
act = React.unstable_act;
act = React.act;
ReactFiberReconciler = require('react-reconciler');
ConcurrentRoot =
require('react-reconciler/src/ReactRootTags').ConcurrentRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('isomorphic act()', () => {
ReactNoop = require('react-noop-renderer');
DiscreteEventPriority =
require('react-reconciler/constants').DiscreteEventPriority;
act = React.unstable_act;
act = React.act;
use = React.use;
Suspense = React.Suspense;
startTransition = React.startTransition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ describe('`act` bypasses Scheduler methods completely,', () => {
}

const root = ReactNoop.createRoot();
const publicAct = React.unstable_act;
const publicAct = React.act;
const prevIsReactActEnvironment = global.IS_REACT_ACT_ENVIRONMENT;
try {
global.IS_REACT_ACT_ENVIRONMENT = true;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-refresh/src/__tests__/ReactFresh-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('ReactFresh', () => {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = React.unstable_act;
act = React.act;
internalAct = require('internal-test-utils').act;

const InternalTestUtils = require('internal-test-utils');
Expand Down Expand Up @@ -3792,7 +3792,7 @@ describe('ReactFresh', () => {
React = require('react');
ReactDOM = require('react-dom');
Scheduler = require('scheduler');
act = React.unstable_act;
act = React.act;
internalAct = require('internal-test-utils').act;

// Important! Inject into the global hook *after* ReactDOM runs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('ReactFlightDOMForm', () => {
ReactServerDOMClient = require('react-server-dom-webpack/client.edge');
ReactDOMServer = require('react-dom/server.edge');
ReactDOMClient = require('react-dom/client');
act = React.unstable_act;
act = React.act;
useFormState = require('react-dom').useFormState;
container = document.createElement('div');
document.body.appendChild(container);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {getPublicInstance} from './ReactFiberConfigTestHost';
import {ConcurrentRoot, LegacyRoot} from 'react-reconciler/src/ReactRootTags';
import {allowConcurrentByDefault} from 'shared/ReactFeatureFlags';

const act = React.unstable_act;
const act = React.act;

// TODO: Remove from public bundle

Expand Down
2 changes: 1 addition & 1 deletion packages/react/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
act as unstable_act,
act,
Children,
Component,
Fragment,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
act as unstable_act,
act,
Children,
Component,
Fragment,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type ChildrenArray<+T> = $ReadOnlyArray<ChildrenArray<T>> | T;
// We can't use export * from in Flow for some reason.
export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
act as unstable_act,
act,
Children,
Component,
Fragment,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/index.modern.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
act as unstable_act,
act,
Children,
Component,
Fragment,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/index.stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
act as unstable_act,
act,
Children,
Component,
Fragment,
Expand Down