From af0234b9b6c183e94a75c416cb25a5e67758277f 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..d46dc1e1095 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 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({ @@ -297,6 +305,7 @@ export function createProfiler< if (!(error && error instanceof WaitForRenderTimeoutError)) { iteratorPosition++; } + (globalThis as any).IS_REACT_ACT_ENVIRONMENT = prevAct; } }, getCurrentRender() {