Use RCTBridgeModule's bridge property instead of [RCTBridge currentBridge] #249
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From the docs of RCTBridge:
What I've found is there exists a race condition where a JS reload triggered very early could potentially result in MMKV install failing in the initial JS context. Much of this is due to the bridge invalidation being asynchronous. It looks something like this:
Arbitrary order:
*Very precisely placed steps to trigger this race condition
Realistically we don't care that the MMKV install in bridge 1 failed, except for the fact that it will throw an error (which can crash the app). Using
_bridge
we have access the correct bridge, even if it's invalidation has started. The install work in the bridge 1 context may be unnecessary and will be later thrown away when the invalidation is finished, but at least it doesn't error. Later MMKV install is called in bridge 2's context and this is what will be used going forward.