Skip to content

Commit

Permalink
fix[react-devtools]: fixed timeline profiler tests (#31261)
Browse files Browse the repository at this point in the history
Fixes tests against React 18 after
#31154:
- Set `supportsTimeline` to true for `Store`.
- Execute `store.profilerStore.startProfiling` after `legacyRender`
import, because this is where `react-dom` is imported and renderer is
registered. We don't yet propagate `isProfiling` flag to newly
registered renderers, when profiling already started see:

https://github.com/facebook/react/blob/d5bba18b5d81f234657586865248c5b6849599cd/packages/react-devtools-shared/src/hook.js#L203-L204
  • Loading branch information
hoxyq authored Oct 15, 2024
1 parent 13411e4 commit ec2bf02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1280,13 +1280,13 @@ describe('Timeline profiler', () => {
});

describe('when profiling', () => {
beforeEach(() => {
utils.act(() => store.profilerStore.startProfiling());
});

describe('with legacy render', () => {
const {render: legacyRender} = getLegacyRenderImplementation();

beforeEach(() => {
utils.act(() => store.profilerStore.startProfiling());
});

// @reactVersion <= 18.2
// @reactVersion >= 18.0
it('should mark sync render without suspends or state updates', () => {
Expand Down Expand Up @@ -1537,6 +1537,10 @@ describe('Timeline profiler', () => {

const {render: modernRender} = getModernRenderImplementation();

beforeEach(() => {
utils.act(() => store.profilerStore.startProfiling());
});

it('should mark concurrent render without suspends or state updates', () => {
utils.act(() => modernRender(<div />));

Expand Down
4 changes: 3 additions & 1 deletion packages/react-devtools-shared/src/__tests__/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ beforeEach(() => {
},
});

const store = new Store(((bridge: any): FrontendBridge));
const store = new Store(((bridge: any): FrontendBridge), {
supportsTimeline: true,
});

const agent = new Agent(((bridge: any): BackendBridge));
const hook = global.__REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down

0 comments on commit ec2bf02

Please sign in to comment.