Skip to content

Commit c5d4dfd

Browse files
fix: avoid reload setup after invalidation
1 parent 27dcad6 commit c5d4dfd

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

packages/react-native/ReactCommon/react/runtime/iostests/RCTInstanceTests.mm

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818

1919
using namespace facebook::react;
2020

21-
@interface RCTInstance (RCTInstanceTests)
22-
- (void)handleBundleLoadingError:(NSError *)error;
23-
@end
24-
2521
@interface FakeEagerModule : NSObject <RCTBridgeModule, RCTTurboModule>
2622
@property (class, readonly) NSCountedSet<NSString *> *initCounts;
2723
@property (class, nullable) void (^onInit)(void);
@@ -225,16 +221,36 @@ - (void)testInitializesDevSettingsAfterBundleLoadFailure
225221

226222
XCTAssertEqual([FakeDevSettings.initCounts countForObject:FakeDevSettingsInitialize], 0u);
227223

228-
id instanceMock = OCMPartialMock(instance);
229-
OCMStub([instanceMock handleBundleLoadingError:[OCMArg any]]);
230224
loadComplete([NSError errorWithDomain:@"RCTInstanceTests" code:1 userInfo:nil], nil);
231225

232226
XCTAssertEqual([FakeDevSettings.initCounts countForObject:FakeDevSettingsInitialize], 1u);
233227

234-
[instanceMock stopMocking];
235228
[instance invalidate];
236229
}
237230

231+
- (void)testDoesNotInitializeDevSettingsAfterInvalidation
232+
{
233+
OCMStub([_mockDelegate unstableModulesRequiringMainQueueSetup]).andReturn(@[]);
234+
235+
XCTestExpectation *loadStarted = [self expectationWithDescription:@"bundle load started"];
236+
__block RCTSourceLoadBlock loadComplete;
237+
OCMStub([_mockDelegate loadBundleAtURL:[OCMArg any] onProgress:[OCMArg any] onComplete:[OCMArg any]])
238+
.andDo(^(NSInvocation *invocation) {
239+
__unsafe_unretained RCTSourceLoadBlock completion;
240+
[invocation getArgument:&completion atIndex:4];
241+
loadComplete = [completion copy];
242+
[loadStarted fulfill];
243+
});
244+
245+
RCTInstance *instance = [self makeInstance];
246+
[self waitForExpectations:@[ loadStarted ] timeout:5.0];
247+
[instance invalidate];
248+
249+
loadComplete([NSError errorWithDomain:@"RCTInstanceTests" code:1 userInfo:nil], nil);
250+
251+
XCTAssertEqual([FakeDevSettings.initCounts countForObject:FakeDevSettingsInitialize], 0u);
252+
}
253+
238254
- (void)testBundleLoadAwaitsMainQueueModuleSetup
239255
{
240256
OCMStub([_mockDelegate unstableModulesRequiringMainQueueSetup]).andReturn(@[ FakeEagerModule.moduleName ]);

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ - (void)handleBundleLoadingError:(NSError *)error
521521
return;
522522
}
523523

524+
[_turboModuleManager moduleForName:"DevSettings"];
524525
RCTRedBox *redBox = [_turboModuleManager moduleForName:"RedBox"];
525526

526527
RCTExecuteOnMainQueue(^{
@@ -563,12 +564,12 @@ - (void)_loadJSBundle:(NSURL *)sourceURL
563564
return;
564565
}
565566

566-
RCTDevSettings *const devSettings =
567-
(RCTDevSettings *)[strongSelf->_turboModuleManager moduleForName:"DevSettings"];
568567
if (error) {
569568
[strongSelf handleBundleLoadingError:error];
570569
return;
571570
}
571+
RCTDevSettings *const devSettings =
572+
(RCTDevSettings *)[strongSelf->_turboModuleManager moduleForName:"DevSettings"];
572573
[strongSelf _loadScriptFromSource:source];
573574
// Set up hot module reloading in Dev only.
574575
[strongSelf->_performanceLogger markStopForTag:RCTPLScriptDownload];

0 commit comments

Comments
 (0)