Repository navigation
Drain ResizeObserver callback microtasks before rendering (#60436) - #60436
Merged
Merged
Conversation
|
@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135358311. |
christophpurrer
approved these changes
Dec 2, 2026
christophpurrer
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
ResizeObserver callback microtasks before renderingResizeObserver callback microtasks before rendering (#60436)
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Dec 2, 2026
) 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
rubennorte
force-pushed
the
export-D135358311
branch
from
December 2, 2026 10:45
7a611a4 to
984adc2
Compare
) 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
rubennorte
force-pushed
the
export-D135358311
branch
from
December 2, 2026 10:59
984adc2 to
f0653b9
Compare
Collaborator
|
This pull request was successfully merged by @rubennorte in 97b3c62 When will my fix make it into a release? | How to file a pick request? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Context
ResizeObservercallbacks 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 invokes each observer's callback individually using Web IDL's callback invocation algorithm. Its step 13.2 performs HTML script cleanup, which triggers 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 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