Based on my analysis of the React Native source code, I can provide you with concrete examples of high priority events that can run the render pipeline in the UI thread.
From examining the React Native source code, I found that React Native uses a priority-based scheduling system with the following hierarchy (defined in <ref_file file="/home/ubuntu/repos/react-native/packages/react-native/ReactCommon/react/renderer/runtimescheduler/SchedulerPriorityUtils.h" />):
- ImmediatePriority (value 1, timeout 0ms) - Highest priority
- UserBlockingPriority (value 2, timeout 250ms) - Second highest priority
- NormalPriority (value 3, timeout 5s)
- LowPriority (value 4, timeout 10s)
- IdlePriority (value 5, timeout 5min)
From the Touchable and Pressable components (<ref_file file="/home/ubuntu/repos/react-native/packages/react-native/Libraries/Components/Touchable/Touchable.js" /> and <ref_file file="/home/ubuntu/repos/react-native/packages/react-native/Libraries/Components/Pressable/Pressable.js" />):
- onPressIn - When a touch begins
- onPressOut - When a touch ends
- onPress - When a tap gesture is completed
- onLongPress - When a long press gesture is detected
- Gesture Responder Events - Touch start, move, and end events
From <ref_file file="/home/ubuntu/repos/react-native/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp" />:
- scheduleWork() method uses
SchedulerPriority::ImmediatePriority(line 47) - executeNowOnTheSameThread() uses
SchedulerPriority::ImmediatePriority(line 156)
The React Native threading model documentation you referenced shows "Discrete event interruption" as a scenario where high priority events can execute the render pipeline synchronously on the UI thread.
From the source code analysis:
-
Event Loop Integration: The <ref_snippet file="/home/ubuntu/repos/react-native/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp" lines="352-379" /> shows the
updateRendering()method that gets called after high priority tasks execute. -
Immediate Execution: High priority events with
ImmediatePriorityhave a 0ms timeout, meaning they execute immediately without yielding to other tasks. -
UI Thread Synchronization: The
executeNowOnTheSameThread()method allows synchronous execution on the UI thread for critical events.
- Touch Events: Classified as discrete events that can interrupt the normal render pipeline
- Gesture Recognition: Touch start, move, and end events are processed with high priority to ensure responsive user interactions
- Immediate Scheduling: Critical UI updates use
ImmediatePriorityto bypass the normal scheduling queue
The React Native architecture ensures that user interaction events like touches, taps, and gestures receive the highest priority to maintain a responsive user interface, allowing them to interrupt ongoing render work and execute synchronously on the UI thread when necessary.
prompt: