Skip to content

Commit

Permalink
iOS: Avoid double reload event when reloading JS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fkgozali authored and facebook-github-bot committed Jun 20, 2018
1 parent 73c4df2 commit 7b9b155
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,9 @@ - (void)setUp {}

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

Expand Down
5 changes: 5 additions & 0 deletions React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
return self;
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)schedulerDidComputeMutationInstructions:(facebook::react::TreeMutationInstructionList)instructions rootTag:(ReactTag)rootTag
{
[_mountingManager mutateComponentViewTreeWithMutationInstructions:instructions
Expand Down
2 changes: 2 additions & 0 deletions React/Fabric/Surface/RCTFabricSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ - (instancetype)initWithSurfacePresenter:(RCTSurfacePresenter *)surfacePresenter

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];

[self _stop];
}

Expand Down

0 comments on commit 7b9b155

Please sign in to comment.