From 383743d1e8694fc8167d93af1a1025de37ef5418 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Mon, 27 Nov 2023 18:36:26 -0700 Subject: [PATCH] Prevent act warnings when using Profiler.takeRender --- src/testing/internal/profile/profile.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/testing/internal/profile/profile.tsx b/src/testing/internal/profile/profile.tsx index 1b3da13965a..542a6eae940 100644 --- a/src/testing/internal/profile/profile.tsx +++ b/src/testing/internal/profile/profile.tsx @@ -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 prevActEnv = (globalThis as any).IS_REACT_ACT_ENVIRONMENT; + (globalThis as any).IS_REACT_ACT_ENVIRONMENT = false; + let error: unknown = undefined; try { return await Profiler.peekRender({ @@ -297,6 +305,7 @@ export function createProfiler< if (!(error && error instanceof WaitForRenderTimeoutError)) { iteratorPosition++; } + (globalThis as any).IS_REACT_ACT_ENVIRONMENT = prevActEnv; } }, getCurrentRender() {