You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 97b3c62
Browse filesBrowse the repository at this point in the historyBrowse files
Drain ResizeObserver callback microtasks before rendering (#60436)
Summary:
## Context
`ResizeObserver` callbacks run during the rendering phase, after the task's normal microtask checkpoint. Jobs queued by those callbacks were left pending until another task arrived, so a later observer or native rendering could run before those jobs.
On the Web, [broadcast active resize observations, §3.4.5 step 2.4](https://drafts.csswg.org/resize-observer/#broadcast-active-resize-observations) invokes each observer's callback individually using [Web IDL's callback invocation algorithm](https://webidl.spec.whatwg.org/#invoke-a-callback-function). Its step 13.2 performs [HTML script cleanup](https://html.spec.whatwg.org/multipage/webappapis.html#clean-up-after-running-script), which triggers a [microtask checkpoint](https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint) when the JavaScript execution-context stack becomes empty. For top-level rendering-phase delivery, that checkpoint drains queued jobs before the invocation returns and the broadcast continues. [HTML's rendering algorithm](https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering) places the ResizeObserver loop before the final UI update.
## Changes
Deliver each observer's native notification separately through a scheduler-owned callback invoker. The invoker calls the notification, performs callback cleanup (including its microtask checkpoint), and then returns to the manager. The manager has no raw microtask-draining capability. Snapshot entries and root their JavaScript identities for the whole broadcast so observer removal and garbage collection cannot invalidate later deliveries.
The task checkpoint keeps its original error-handling policy. Uncaught observer checkpoint and notification errors unwind the observer machinery before clearing queued work and invoking the host fatal handler, then stop the rendering step. This prevents pending callbacks from accessing delegates destroyed during teardown. Handled observer exceptions continue normally. Keep the existing microtask-checkpoint reentry protection, without adding task/rendering-phase state or redundant entry guards.
Add public-behavior integration coverage for FIFO promise/await/nested jobs, inter-observer ordering, pre-mount execution, deeper-target observations, nested measure callbacks, cancellation and error recovery. Update existing state-update tests to distinguish a real later rendering task from jobs that were previously stuck until an arbitrary wake.
Changelog:
[General][Fixed] - Run ResizeObserver callback microtasks before later observers and native rendering.
Reviewed By: christophpurrer
Differential Revision: D135358311
Pull Request resolved: #60436
Copy file name to clipboardExpand all lines: packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeSchedulerResizeObserverDelegate.h
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -10,14 +10,19 @@
10
10
#include<react/cxxstableapi/FrameworksGuard.h>
11
11
12
12
#include<jsi/jsi.h>
13
+
#include<functional>
13
14
14
15
namespacefacebook::react {
15
16
16
17
classRuntimeSchedulerResizeObserverDelegate {
17
18
public:
19
+
using CallbackInvoker = std::function<void(const std::function<void()> &)>;
0 commit comments