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

Concurrent rendering in ReactDevToolsHooksIntegration-test #28522

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Changes from 2 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,6 +46,7 @@ describe('React hooks DevTools integration', () => {
act = ReactTestRenderer.act;
});

// @gate __DEV__
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this gating condition is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was due to the act usage failing in production env. There was already some gating here for the concurrent mode test case so I followed that pattern. But took a look again and updating the act import to the internal utility resolves all the gating on this module. Updated PR

it('should support editing useState hooks', async () => {
let setCountFn;

Expand All @@ -55,7 +56,12 @@ describe('React hooks DevTools integration', () => {
return <div>count:{count}</div>;
}

const renderer = ReactTestRenderer.create(<MyComponent />);
let renderer;
await act(() => {
renderer = ReactTestRenderer.create(<MyComponent />, {
unstable_isConcurrent: true,
});
});
expect(renderer.toJSON()).toEqual({
type: 'div',
props: {},
Expand Down Expand Up @@ -84,6 +90,7 @@ describe('React hooks DevTools integration', () => {
}
});

// @gate __DEV__
it('should support editable useReducer hooks', async () => {
const initialData = {foo: 'abc', bar: 123};

Expand All @@ -107,7 +114,12 @@ describe('React hooks DevTools integration', () => {
);
}

const renderer = ReactTestRenderer.create(<MyComponent />);
let renderer;
await act(() => {
renderer = ReactTestRenderer.create(<MyComponent />, {
unstable_isConcurrent: true,
});
});
expect(renderer.toJSON()).toEqual({
type: 'div',
props: {},
Expand Down Expand Up @@ -138,6 +150,7 @@ describe('React hooks DevTools integration', () => {

// This test case is based on an open source bug report:
// https://github.com/facebookincubator/redux-react-hook/issues/34#issuecomment-466693787
// @gate __DEV__
it('should handle interleaved stateful hooks (e.g. useState) and non-stateful hooks (e.g. useContext)', async () => {
const MyContext = React.createContext(1);

Expand All @@ -155,7 +168,12 @@ describe('React hooks DevTools integration', () => {
return <div>count:{count}</div>;
}

const renderer = ReactTestRenderer.create(<MyComponent />);
let renderer;
await act(() => {
renderer = ReactTestRenderer.create(<MyComponent />, {
unstable_isConcurrent: true,
});
});
expect(renderer.toJSON()).toEqual({
type: 'div',
props: {},
Expand Down Expand Up @@ -183,6 +201,7 @@ describe('React hooks DevTools integration', () => {
}
});

// @gate __DEV__
it('should support overriding suspense in legacy mode', async () => {
if (__DEV__) {
// Lock the first render
Expand All @@ -192,14 +211,17 @@ describe('React hooks DevTools integration', () => {
function MyComponent() {
return 'Done';
}

const renderer = ReactTestRenderer.create(
<div>
<React.Suspense fallback={'Loading'}>
<MyComponent />
</React.Suspense>
</div>,
);
let renderer;
await act(() => {
renderer = ReactTestRenderer.create(
<div>
<React.Suspense fallback={'Loading'}>
<MyComponent />
</React.Suspense>
</div>,
{unstable_isConcurrent: true},
);
});
const fiber = renderer.root._currentFiber().child;
if (__DEV__) {
// First render was locked
Expand Down Expand Up @@ -254,7 +276,7 @@ describe('React hooks DevTools integration', () => {
<MyComponent />
</React.Suspense>
</div>,
{isConcurrent: true},
{unstable_isConcurrent: true},
),
);

Expand Down