Skip to content

Commit

Permalink
Prevent act warnings when using Profiler.takeRender
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Nov 28, 2023
1 parent fe2cf17 commit af0234b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/testing/internal/profile/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ export function createProfiler<
});
},
async takeRender(options: NextRenderOptions = {}) {
// In many cases we do not control the resolution of the suspended
// promise which results in noisy tests when using this utility. Instead,
// we disable act warnings when using this utility.
//
// https://github.com/reactwg/react-18/discussions/102
const prevAct = (globalThis as any).IS_REACT_ACT_ENVIRONMENT;
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = false;

let error: unknown = undefined;
try {
return await Profiler.peekRender({
Expand All @@ -297,6 +305,7 @@ export function createProfiler<
if (!(error && error instanceof WaitForRenderTimeoutError)) {
iteratorPosition++;
}
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = prevAct;
}
},
getCurrentRender() {
Expand Down

0 comments on commit af0234b

Please sign in to comment.