From 076d647747a8fd8ab1bc5232d5d7eb7bb69ca297 Mon Sep 17 00:00:00 2001 From: acdlite Date: Tue, 2 May 2023 15:35:13 -0700 Subject: [PATCH] Fix: Update while suspended fails to interrupt (#26739) Summary: This fixes a bug with `use` where if you update a component that's currently suspended, React will sometimes mistake it for a render phase update. This happens because we don't reset `currentlyRenderingFiber` until the suspended is unwound. And with `use`, that can happen asynchronously, most commonly when the work loop is suspended during a transition. The fix is to make sure `currentlyRenderingFiber` is only set when we're in the middle of rendering, which used to be true until `use` was introduced. More specifically this means clearing `currentlyRenderingFiber` when something throws and setting it again when we resume work. In many cases, this bug will fail "gracefully" because the update is still added to the queue; it's not dropped completely. It's also somewhat rare because it has to be the exact same component that's currently suspended. But it's still a bug. I wrote a regression test that shows a sync update failing to interrupt a suspended component. DiffTrain build for commit https://github.com/facebook/react/commit/18282f881dae106ebf6240aa52c8c02fe7c8d6f2. Changelog: [Internal] << DO NOT EDIT BELOW THIS LINE >> Reviewed By: poteto Differential Revision: D45407314 Pulled By: tyao1 fbshipit-source-id: 1303940cc34db28087563c20a187779a51d133de --- packages/react-native/Libraries/Renderer/REVISION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Renderer/REVISION b/packages/react-native/Libraries/Renderer/REVISION index 53c23329459..17d004e0f4c 100644 --- a/packages/react-native/Libraries/Renderer/REVISION +++ b/packages/react-native/Libraries/Renderer/REVISION @@ -1 +1 @@ -540bab085d571789f4562565eebfd0db9f36345c +18282f881dae106ebf6240aa52c8c02fe7c8d6f2