Skip to content

Commit e71fc4e

Browse files
alanjhughesmeta-codesync[bot]
authored andcommitted
Fix RCTDevSettings init (#57409)
Summary: #54258 made RCTPackagerConnection a per RCTDevSettings instance and creates it in init. The issue is that init isn't the only way these instances are built, anything constructed through the public initWithDataSource bypasses init entirely, so initWithDataSource never creates _packagerConnection and it stays nil. Those instances silently stop receiving packager commands like reload and devMenu, because the connection they would register handlers on and receive over does not exist. This moves the creation into initWithDataSource, so every construction path gets a connection. -init still delegates to initWithDataSource:, so the default path is unchanged. ## Changelog: [IOS] [FIXED] - Create the RCTDevSettings packager connection in initWithDataSource so instances built that way also receive packager commands Pull Request resolved: #57409 Test Plan: - [[RCTDevSettings alloc] init].packagerConnection is non-nil (unchanged). - [[RCTDevSettings alloc] initWithDataSource:dataSource]. packagerConnection is non-nil after this change (it was nil before). - Verified in a host that subclasses RCTDevSettings via initWithDataSource (Expo Go's scoped dev settings), reload and devMenu from the CLI now reach the app over the packager connection. Before this change they were dropped because the subclass had a nil connection. Reviewed By: vzaidman, cortinico Differential Revision: D113387408 Pulled By: cipolleschi fbshipit-source-id: bdf4b5b431c6870afd652e980022fb43c88bcb0c
1 parent 22cfb5c commit e71fc4e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/react-native/React/CoreModules/RCTDevSettings.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ - (instancetype)init
156156
};
157157
RCTDevSettingsUserDefaultsDataSource *dataSource =
158158
[[RCTDevSettingsUserDefaultsDataSource alloc] initWithDefaultValues:defaultValues];
159-
#if RCT_DEV
160-
_packagerConnection = [RCTPackagerConnection new];
161-
#endif
162159
_isShakeGestureEnabled = true;
163160
return [self initWithDataSource:dataSource];
164161
}
@@ -176,6 +173,9 @@ - (BOOL)_isBridgeMode
176173
- (instancetype)initWithDataSource:(id<RCTDevSettingsDataSource>)dataSource
177174
{
178175
if (self = [super init]) {
176+
#if RCT_DEV
177+
_packagerConnection = [RCTPackagerConnection new];
178+
#endif
179179
_dataSource = dataSource;
180180

181181
[[NSNotificationCenter defaultCenter] addObserver:self

0 commit comments

Comments
 (0)