Skip to content

Commit 7b9b155

Browse files
fkgozalifacebook-github-bot
authored andcommitted
iOS: Avoid double reload event when reloading JS
Summary: @public The bridge may send the reload event twice when reloading JS in some rare condition. The 2nd one was actually when the "new" bridge wasn't valid yet, so log an error if that happens. This may happen if the connection to Metro server gets into a weird state. Restarting Metro would solve the problem. The issue was that `RCTBridgeWillReloadNotification` fired twice for each reload with metro connected. Reviewed By: mmmulani Differential Revision: D8509448 fbshipit-source-id: 647fb98c0a97503409a10451b8f152145947ae20
1 parent 73c4df2 commit 7b9b155

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Diff for: React/CxxBridge/RCTCxxBridge.mm

+3
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ - (void)setUp {}
876876

877877
- (void)reload
878878
{
879+
if (!_valid) {
880+
RCTLogError(@"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.", self);
881+
}
879882
[_parentBridge reload];
880883
}
881884

Diff for: React/Fabric/RCTSurfacePresenter.mm

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
6161
return self;
6262
}
6363

64+
- (void)dealloc
65+
{
66+
[[NSNotificationCenter defaultCenter] removeObserver:self];
67+
}
68+
6469
- (void)schedulerDidComputeMutationInstructions:(facebook::react::TreeMutationInstructionList)instructions rootTag:(ReactTag)rootTag
6570
{
6671
[_mountingManager mutateComponentViewTreeWithMutationInstructions:instructions

Diff for: React/Fabric/Surface/RCTFabricSurface.mm

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ - (instancetype)initWithSurfacePresenter:(RCTSurfacePresenter *)surfacePresenter
9090

9191
- (void)dealloc
9292
{
93+
[[NSNotificationCenter defaultCenter] removeObserver:self];
94+
9395
[self _stop];
9496
}
9597

0 commit comments

Comments
 (0)