Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/react-native/React/Fabric/AppleEventBeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ class AppleEventBeat : public EventBeat, public RunLoopObserver::Delegate {
WindowLayerResolver windowLayerResolver_;
NSMapTable<CALayer *, RCTEventBeatFlusherLayer *> *layers_;
void (^onDisplay_)(void);

/*
* Whether a display phase has already induced in the current run loop turn.
*
* The beat a display phase induces runs the whole event loop tick on the
* main thread, mounting included, so a `VirtualView` whose layout metrics
* change during that mount emits another synchronous request from inside the
* display it is servicing. Core Animation honours `setNeedsDisplay` made
* during a display by running the commit's layout and display phases again,
* with no bound, so without this flag one commit can perform an unbounded
* number of blocking JavaScript round trips. Requests that arrive after the
* first induce keep the ordinary run loop observer timing.
*/
mutable bool didInduceInCurrentTurn_{false};
};

} // namespace facebook::react
7 changes: 7 additions & 0 deletions packages/react-native/React/Fabric/AppleEventBeat.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ - (void)display
if (!owner) {
return;
}
if (this->didInduceInCurrentTurn_) {
return;
}
this->didInduceInCurrentTurn_ = true;
this->induce();
};

Expand Down Expand Up @@ -117,6 +121,9 @@ - (void)display
RunLoopObserver::Activity /*activity*/) const noexcept
{
react_native_assert(delegate == this);
// This observer runs before Core Animation's commit observer, so it is the
// start of the turn whose display phase `didInduceInCurrentTurn_` bounds.
didInduceInCurrentTurn_ = false;
induce();
}

Expand Down
Loading