From 92d743a9ab5d9f9b57725b6e6b86178a6c2a1549 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Mon, 28 Oct 2024 13:17:43 -0700 Subject: [PATCH] surface setup issues in EventBeat and Scheduler (#47253) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47253 changelog: [internal] Add assert statements to make sure EventBeat and Scheduler classes are correctly setup. Scheduler must receive RuntimeScheduler through ContextContainer. Callers of EventBeat must set beatCallback before calling request. Reviewed By: javache Differential Revision: D65001802 fbshipit-source-id: 5e044e1e6b0249bc89c11cccd51801add2e85b88 --- .../ReactCommon/react/renderer/core/EventBeat.cpp | 4 ++++ .../react/renderer/scheduler/Scheduler.cpp | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/EventBeat.cpp b/packages/react-native/ReactCommon/react/renderer/core/EventBeat.cpp index 9a9fd5266d798a..e00ad5fb785482 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/EventBeat.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/EventBeat.cpp @@ -7,6 +7,7 @@ #include "EventBeat.h" +#include #include #include @@ -18,6 +19,9 @@ EventBeat::EventBeat( : ownerBox_(std::move(ownerBox)), runtimeScheduler_(runtimeScheduler) {} void EventBeat::request() const { + react_native_assert( + beatCallback_ && + "Unexpected state: EventBeat::setBeatCallback was not called before EventBeat::request."); isRequested_ = true; } diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp index f5f37c91792def..432450ae43fae9 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -54,17 +54,18 @@ Scheduler::Scheduler( auto weakRuntimeScheduler = contextContainer_->find>( "RuntimeScheduler"); - auto runtimeScheduler = weakRuntimeScheduler.has_value() - ? weakRuntimeScheduler.value().lock() - : nullptr; + react_native_assert( + weakRuntimeScheduler.has_value() && + "Unexpected state: RuntimeScheduler was not provided."); + + auto runtimeScheduler = weakRuntimeScheduler.value().lock(); - if (runtimeScheduler && ReactNativeFeatureFlags::enableUIConsistency()) { + if (ReactNativeFeatureFlags::enableUIConsistency()) { runtimeScheduler->setShadowTreeRevisionConsistencyManager( uiManager->getShadowTreeRevisionConsistencyManager()); } - if (runtimeScheduler && - ReactNativeFeatureFlags::enableReportEventPaintTime()) { + if (ReactNativeFeatureFlags::enableReportEventPaintTime()) { runtimeScheduler->setEventTimingDelegate(eventPerformanceLogger_.get()); }