mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Capture idle callback before running it (#54984)
Summary: Fixes https://github.com/facebook/react-native/issues/54983 https://github.com/facebook/react-native/issues/54983 has more details, but in short, this code here: ```kotlin currentIdleCallbackRunnable?.cancel() currentIdleCallbackRunnable = IdleCallbackRunnable(frameTimeNanos) reactApplicationContext.runOnJSQueueThread(currentIdleCallbackRunnable) ``` If `currentIdleCallbackRunnable` change between line 2 and line 3 (which is known to happen), the wrong runnable would be sent to be run. The fix is to simply capture it in a local variable before passing it to be run ```kotlin currentIdleCallbackRunnable?.cancel() val idleCallbackRunnable = IdleCallbackRunnable(frameTimeNanos) currentIdleCallbackRunnable = idleCallbackRunnable reactApplicationContext.runOnJSQueueThread(idleCallbackRunnable) ``` ## Changelog: [ANDROID] [FIXED] - Capture idle callback before running it Pull Request resolved: https://github.com/facebook/react-native/pull/54984 Test Plan: Unfortunately this is a pretty speculative change. That said, since the change is so simple, the worst thing that can happen is nothing. I have also run it in production here with no known issues https://github.com/bluesky-social/social-app/pull/9436 Reviewed By: cortinico Differential Revision: D90120471 Pulled By: lunaleaps fbshipit-source-id: c853a976be999fa883a5835fd5e8ac75a8699681
This commit is contained in:
1 parent
749b8f6cf7
commit
90e48d6031
1 file changed
+4
-2
+4
-2
@@ -327,9 +327,11 @@ public open class JavaTimerManager(
|
||||
// If the JS thread is busy for multiple frames we cancel any other pending runnable.
|
||||
// We also capture the idleCallbackRunnable to tentatively fix:
|
||||
// https://github.com/facebook/react-native/issues/44842
|
||||
// https://github.com/facebook/react-native/issues/54983
|
||||
currentIdleCallbackRunnable?.cancel()
|
||||
currentIdleCallbackRunnable = IdleCallbackRunnable(frameTimeNanos)
|
||||
reactApplicationContext.runOnJSQueueThread(currentIdleCallbackRunnable)
|
||||
val idleCallbackRunnable = IdleCallbackRunnable(frameTimeNanos)
|
||||
currentIdleCallbackRunnable = idleCallbackRunnable
|
||||
reactApplicationContext.runOnJSQueueThread(idleCallbackRunnable)
|
||||
reactChoreographer.postFrameCallback(ReactChoreographer.CallbackType.IDLE_EVENT, this)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user