Skip to content

Commit

Permalink
Bridge Mode: Make TurboModule invalidation more robust (#38357)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38357

## Context
On iOS, NSNotificationCenter facilitates event dispatch:
- People can dispatch events **to** objects.
- People can subscribe to events coming **from** objects.

(By specifying objects, NSNotificationCenter also implements event filtering).

The TuboModule system uses NSNotificationCenter to implement module invalidation:
- The bridge dispatches invalidation notifications to its parentBridge object.
- The TurboModuleManager listens to those invalidation notifications from the parentBridge object.

## Problem
In some apps, the TurboModuleManager never invalidates modules.

The bridge dispatches its invalidation notifications to nil: the parentBridge gets deallocated before bridge invalidation finishes.

But, the TurboModuleManager never receives those invalidation notifications: it is listening to invalidation notifications coming from a non-nil parentBridge.

## Fix
Make the TurboModuleManager listen to invalidation notifications from all objects. It will just manually noop invalidation if the notification's bridge object doesn't match its own bridge object. (This is existing logic).

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D47485910

fbshipit-source-id: 163403ef01f7d164a0e482f0f770a801d572503b
  • Loading branch information
fkgozali authored and facebook-github-bot committed Jul 16, 2023
1 parent 4c94454 commit 8ab9a77
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(bridgeWillInvalidateModules:)
name:RCTBridgeWillInvalidateModulesNotification
object:_bridge.parentBridge];
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(bridgeDidInvalidateModules:)
name:RCTBridgeDidInvalidateModulesNotification
object:_bridge.parentBridge];
object:nil];
}
return self;
}
Expand Down

0 comments on commit 8ab9a77

Please sign in to comment.