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

Use concurrent root in RTR #28498

Merged
merged 3 commits into from
Mar 26, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,45 +46,40 @@ describe('ErrorBoundaryReconciliation', () => {
fail ? <InvalidType /> : <span prop="BrokenRender" />;
});

[true, false].forEach(isConcurrent => {
async function sharedTest(ErrorBoundary, fallbackTagName) {
let renderer;
async function sharedTest(ErrorBoundary, fallbackTagName) {
let renderer;

await act(() => {
renderer = ReactTestRenderer.create(
<ErrorBoundary fallbackTagName={fallbackTagName}>
<BrokenRender fail={false} />
</ErrorBoundary>,
{unstable_isConcurrent: true},
);
});
expect(renderer).toMatchRenderedOutput(<span prop="BrokenRender" />);
await expect(async () => {
await act(() => {
renderer = ReactTestRenderer.create(
renderer.update(
<ErrorBoundary fallbackTagName={fallbackTagName}>
<BrokenRender fail={false} />
<BrokenRender fail={true} />
</ErrorBoundary>,
{unstable_isConcurrent: isConcurrent},
);
});
expect(renderer).toMatchRenderedOutput(<span prop="BrokenRender" />);

await expect(async () => {
await act(() => {
renderer.update(
<ErrorBoundary fallbackTagName={fallbackTagName}>
<BrokenRender fail={true} />
</ErrorBoundary>,
);
});
}).toErrorDev(isConcurrent ? ['invalid', 'invalid'] : ['invalid']);
const Fallback = fallbackTagName;
expect(renderer).toMatchRenderedOutput(<Fallback prop="ErrorBoundary" />);
}
}).toErrorDev(['invalid', 'invalid']);
const Fallback = fallbackTagName;
expect(renderer).toMatchRenderedOutput(<Fallback prop="ErrorBoundary" />);
}

describe(isConcurrent ? 'concurrent' : 'sync', () => {
it('componentDidCatch can recover by rendering an element of the same type', () =>
sharedTest(DidCatchErrorBoundary, 'span'));
it('componentDidCatch can recover by rendering an element of the same type', () =>
sharedTest(DidCatchErrorBoundary, 'span'));

it('componentDidCatch can recover by rendering an element of a different type', () =>
sharedTest(DidCatchErrorBoundary, 'div'));
it('componentDidCatch can recover by rendering an element of a different type', () =>
sharedTest(DidCatchErrorBoundary, 'div'));

it('getDerivedStateFromError can recover by rendering an element of the same type', () =>
sharedTest(GetDerivedErrorBoundary, 'span'));
it('getDerivedStateFromError can recover by rendering an element of the same type', () =>
sharedTest(GetDerivedErrorBoundary, 'span'));

it('getDerivedStateFromError can recover by rendering an element of a different type', () =>
sharedTest(GetDerivedErrorBoundary, 'div'));
});
});
it('getDerivedStateFromError can recover by rendering an element of a different type', () =>
sharedTest(GetDerivedErrorBoundary, 'div'));
});
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ describe('ReactLazy', () => {
});

describe('legacy mode', () => {
// @gate !disableLegacyMode
it('mount and reorder lazy elements (legacy mode)', async () => {
class Child extends React.Component {
componentDidMount() {
Expand Down Expand Up @@ -1520,6 +1521,7 @@ describe('ReactLazy', () => {
expect(root).toMatchRenderedOutput('ba');
});

// @gate !disableLegacyMode
it('mount and reorder lazy types (legacy mode)', async () => {
class Child extends React.Component {
componentDidMount() {
Expand Down
10 changes: 7 additions & 3 deletions packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {ConcurrentRoot, LegacyRoot} from 'react-reconciler/src/ReactRootTags';
import {
allowConcurrentByDefault,
enableReactTestRendererWarning,
disableLegacyMode,
} from 'shared/ReactFeatureFlags';

const act = React.act;
Expand Down Expand Up @@ -485,16 +486,19 @@ function create(
}

let createNodeMock = defaultTestOptions.createNodeMock;
let isConcurrent = false;
const isConcurrentOnly =
disableLegacyMode === true &&
global.IS_REACT_NATIVE_TEST_ENVIRONMENT !== true;
let isConcurrent = isConcurrentOnly;
let isStrictMode = false;
let concurrentUpdatesByDefault = null;
if (typeof options === 'object' && options !== null) {
if (typeof options.createNodeMock === 'function') {
// $FlowFixMe[incompatible-type] found when upgrading Flow
createNodeMock = options.createNodeMock;
}
if (options.unstable_isConcurrent === true) {
isConcurrent = true;
if (isConcurrentOnly === false) {
isConcurrent = options.unstable_isConcurrent;
}
if (options.unstable_strictMode === true) {
isStrictMode = true;
Expand Down
Loading