Skip to content

Commit b8dc216

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Forward declare CDP reporters and ViewTransitionModule in Scheduler.h (#58136)
Summary: Pull Request resolved: #58136 Under the C++ Stable API RFC, `react/renderer/scheduler:scheduler` is a "for frameworks" module while `react/performance/cdpmetrics:cdpmetrics` and `react/renderer/viewtransition:viewtransition` are private. `Scheduler.h` is an exported header of the scheduler target and included all three private headers, so it transitively exposed them to consumers. `ViewTransitionModule.h` already carries the private-tier guard, so this was an active violation and not just a latent one. `Scheduler.h` only needs these types for data members. `viewTransitionModule_` was already a `std::shared_ptr`, so a forward declaration is sufficient. The two CDP reporters were held as `std::optional`, which requires a complete type, so they become `std::unique_ptr`. They are constructed conditionally behind feature flags and only ever handed to `PerformanceEntryReporter` as raw pointers, so ownership and lifetime are unchanged. `~Scheduler()` is already out of line, so the incomplete types are fine. `<optional>` and `<shared_mutex>` are now included explicitly, since they were previously pulled in transitively through the cdpmetrics headers. `Scheduler.h` is the only header in ReactCommon that reached either module, so both are now cleanly private. No build config change is needed: `cdpmetrics` and `viewtransition` are already non-exported deps of the scheduler target. Changelog: [Internal] Reviewed By: javache Differential Revision: D116909092 fbshipit-source-id: 65fe23320d1aefefbab40c02bb9a540901f44ba2
1 parent bc64b26 commit b8dc216

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <cxxreact/TraceSection.h>
1414
#include <react/debug/react_native_assert.h>
1515
#include <react/featureflags/ReactNativeFeatureFlags.h>
16+
#include <react/performance/cdpmetrics/CdpMetricsReporter.h>
17+
#include <react/performance/cdpmetrics/CdpPerfIssuesReporter.h>
1618
#include <react/renderer/animationbackend/AnimationBackend.h>
1719
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
1820
#include <react/renderer/core/EventQueueProcessor.h>
@@ -23,6 +25,7 @@
2325
#include <react/renderer/uimanager/LayoutEventEmitter.h>
2426
#include <react/renderer/uimanager/UIManager.h>
2527
#include <react/renderer/uimanager/UIManagerBinding.h>
28+
#include <react/renderer/viewtransition/ViewTransitionModule.h>
2629
#include <mutex>
2730

2831
namespace facebook::react {
@@ -43,13 +46,15 @@ Scheduler::Scheduler(
4346

4447
if (ReactNativeFeatureFlags::enableBridgelessArchitecture() &&
4548
ReactNativeFeatureFlags::cdpInteractionMetricsEnabled()) {
46-
cdpMetricsReporter_.emplace(CdpMetricsReporter{runtimeExecutor_});
47-
performanceEntryReporter_->addEventListener(&*cdpMetricsReporter_);
49+
cdpMetricsReporter_ =
50+
std::make_unique<CdpMetricsReporter>(runtimeExecutor_);
51+
performanceEntryReporter_->addEventListener(cdpMetricsReporter_.get());
4852
}
4953

5054
if (ReactNativeFeatureFlags::perfIssuesEnabled()) {
51-
cdpPerfIssuesReporter_.emplace(CdpPerfIssuesReporter{runtimeExecutor_});
52-
performanceEntryReporter_->addEventListener(&*cdpPerfIssuesReporter_);
55+
cdpPerfIssuesReporter_ =
56+
std::make_unique<CdpPerfIssuesReporter>(runtimeExecutor_);
57+
performanceEntryReporter_->addEventListener(cdpPerfIssuesReporter_.get());
5358
}
5459

5560
eventPerformanceLogger_ =
@@ -206,10 +211,11 @@ Scheduler::~Scheduler() {
206211
uiManager_->setViewTransitionDelegate(nullptr);
207212

208213
if (cdpMetricsReporter_) {
209-
performanceEntryReporter_->removeEventListener(&*cdpMetricsReporter_);
214+
performanceEntryReporter_->removeEventListener(cdpMetricsReporter_.get());
210215
}
211216
if (cdpPerfIssuesReporter_) {
212-
performanceEntryReporter_->removeEventListener(&*cdpPerfIssuesReporter_);
217+
performanceEntryReporter_->removeEventListener(
218+
cdpPerfIssuesReporter_.get());
213219
}
214220

215221
// Then, let's verify that the requirement was satisfied.

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
#include <atomic>
1313
#include <memory>
14+
#include <optional>
15+
#include <shared_mutex>
1416
#include <vector>
1517

1618
#include <ReactCommon/RuntimeExecutor.h>
17-
#include <react/performance/cdpmetrics/CdpMetricsReporter.h>
18-
#include <react/performance/cdpmetrics/CdpPerfIssuesReporter.h>
1919
#include <react/performance/timeline/PerformanceEntryReporter.h>
2020
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
2121
#include <react/renderer/core/ComponentDescriptor.h>
@@ -31,11 +31,14 @@
3131
#include <react/renderer/uimanager/UIManagerAnimationDelegate.h>
3232
#include <react/renderer/uimanager/UIManagerBinding.h>
3333
#include <react/renderer/uimanager/UIManagerDelegate.h>
34-
#include <react/renderer/viewtransition/ViewTransitionModule.h>
3534
#include <react/utils/ContextContainer.h>
3635

3736
namespace facebook::react {
3837

38+
class CdpMetricsReporter;
39+
class CdpPerfIssuesReporter;
40+
class ViewTransitionModule;
41+
3942
/*
4043
* Scheduler coordinates Shadow Tree updates and event flows.
4144
*/
@@ -142,8 +145,8 @@ class Scheduler final : public UIManagerDelegate {
142145
std::shared_ptr<std::optional<const EventDispatcher>> eventDispatcher_;
143146

144147
std::shared_ptr<PerformanceEntryReporter> performanceEntryReporter_;
145-
std::optional<CdpMetricsReporter> cdpMetricsReporter_;
146-
std::optional<CdpPerfIssuesReporter> cdpPerfIssuesReporter_;
148+
std::unique_ptr<CdpMetricsReporter> cdpMetricsReporter_;
149+
std::unique_ptr<CdpPerfIssuesReporter> cdpPerfIssuesReporter_;
147150
std::shared_ptr<EventPerformanceLogger> eventPerformanceLogger_;
148151

149152
/**

0 commit comments

Comments
 (0)