Skip to content

Commit 8ba5ae0

Browse files
author
Jack Pope
committed
Only concurrent render in RTR
1 parent 1f9befe commit 8ba5ae0

File tree

8 files changed

+536
-273
lines changed

8 files changed

+536
-273
lines changed

packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,40 @@ describe('ErrorBoundaryReconciliation', () => {
4646
fail ? <InvalidType /> : <span prop="BrokenRender" />;
4747
});
4848

49-
[true, false].forEach(isConcurrent => {
50-
async function sharedTest(ErrorBoundary, fallbackTagName) {
51-
let renderer;
49+
async function sharedTest(ErrorBoundary, fallbackTagName) {
50+
let renderer;
5251

52+
await act(() => {
53+
renderer = ReactTestRenderer.create(
54+
<ErrorBoundary fallbackTagName={fallbackTagName}>
55+
<BrokenRender fail={false} />
56+
</ErrorBoundary>,
57+
{unstable_isConcurrent: true},
58+
);
59+
});
60+
expect(renderer).toMatchRenderedOutput(<span prop="BrokenRender" />);
61+
await expect(async () => {
5362
await act(() => {
54-
renderer = ReactTestRenderer.create(
63+
renderer.update(
5564
<ErrorBoundary fallbackTagName={fallbackTagName}>
56-
<BrokenRender fail={false} />
65+
<BrokenRender fail={true} />
5766
</ErrorBoundary>,
58-
{unstable_isConcurrent: isConcurrent},
5967
);
6068
});
61-
expect(renderer).toMatchRenderedOutput(<span prop="BrokenRender" />);
62-
63-
await expect(async () => {
64-
await act(() => {
65-
renderer.update(
66-
<ErrorBoundary fallbackTagName={fallbackTagName}>
67-
<BrokenRender fail={true} />
68-
</ErrorBoundary>,
69-
);
70-
});
71-
}).toErrorDev(isConcurrent ? ['invalid', 'invalid'] : ['invalid']);
72-
const Fallback = fallbackTagName;
73-
expect(renderer).toMatchRenderedOutput(<Fallback prop="ErrorBoundary" />);
74-
}
69+
}).toErrorDev(['invalid', 'invalid']);
70+
const Fallback = fallbackTagName;
71+
expect(renderer).toMatchRenderedOutput(<Fallback prop="ErrorBoundary" />);
72+
}
7573

76-
describe(isConcurrent ? 'concurrent' : 'sync', () => {
77-
it('componentDidCatch can recover by rendering an element of the same type', () =>
78-
sharedTest(DidCatchErrorBoundary, 'span'));
74+
it('componentDidCatch can recover by rendering an element of the same type', () =>
75+
sharedTest(DidCatchErrorBoundary, 'span'));
7976

80-
it('componentDidCatch can recover by rendering an element of a different type', () =>
81-
sharedTest(DidCatchErrorBoundary, 'div'));
77+
it('componentDidCatch can recover by rendering an element of a different type', () =>
78+
sharedTest(DidCatchErrorBoundary, 'div'));
8279

83-
it('getDerivedStateFromError can recover by rendering an element of the same type', () =>
84-
sharedTest(GetDerivedErrorBoundary, 'span'));
80+
it('getDerivedStateFromError can recover by rendering an element of the same type', () =>
81+
sharedTest(GetDerivedErrorBoundary, 'span'));
8582

86-
it('getDerivedStateFromError can recover by rendering an element of a different type', () =>
87-
sharedTest(GetDerivedErrorBoundary, 'div'));
88-
});
89-
});
83+
it('getDerivedStateFromError can recover by rendering an element of a different type', () =>
84+
sharedTest(GetDerivedErrorBoundary, 'div'));
9085
});

packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ describe('ReactLazy', () => {
14511451
});
14521452

14531453
describe('legacy mode', () => {
1454+
// @gate !disableLegacyMode
14541455
it('mount and reorder lazy elements (legacy mode)', async () => {
14551456
class Child extends React.Component {
14561457
componentDidMount() {
@@ -1520,6 +1521,7 @@ describe('ReactLazy', () => {
15201521
expect(root).toMatchRenderedOutput('ba');
15211522
});
15221523

1524+
// @gate !disableLegacyMode
15231525
it('mount and reorder lazy types (legacy mode)', async () => {
15241526
class Child extends React.Component {
15251527
componentDidMount() {

packages/react-test-renderer/src/ReactTestRenderer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {ConcurrentRoot, LegacyRoot} from 'react-reconciler/src/ReactRootTags';
5555
import {
5656
allowConcurrentByDefault,
5757
enableReactTestRendererWarning,
58+
disableLegacyMode,
5859
} from 'shared/ReactFeatureFlags';
5960

6061
const act = React.act;
@@ -485,16 +486,19 @@ function create(
485486
}
486487

487488
let createNodeMock = defaultTestOptions.createNodeMock;
488-
let isConcurrent = false;
489+
const isConcurrentOnly =
490+
disableLegacyMode === true &&
491+
global.IS_REACT_NATIVE_TEST_ENVIRONMENT !== true;
492+
let isConcurrent = isConcurrentOnly;
489493
let isStrictMode = false;
490494
let concurrentUpdatesByDefault = null;
491495
if (typeof options === 'object' && options !== null) {
492496
if (typeof options.createNodeMock === 'function') {
493497
// $FlowFixMe[incompatible-type] found when upgrading Flow
494498
createNodeMock = options.createNodeMock;
495499
}
496-
if (options.unstable_isConcurrent === true) {
497-
isConcurrent = true;
500+
if (!isConcurrentOnly) {
501+
isConcurrent = options.unstable_isConcurrent;
498502
}
499503
if (options.unstable_strictMode === true) {
500504
isStrictMode = true;

0 commit comments

Comments
 (0)