mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 22:41:18 +08:00
Protect against JS module call race condition while initializing react instance
Summary: Fixes a race condition where JS module functions could be called in between ##initializeWithInstance(catalystInstance);## and ##CatalystInstance#runJSBundle##, before the BatchedBridge in JS was set up. We now guarantee that all JS module methods that are called after `ReactContext#hasActiveCatalystInstance()` returns true will have the batched bridge created and ready to use. Reviewed By: lexs Differential Revision: D3258651 fb-gh-sync-id: 66e66533cc86d185e7c865376d6a5cdc6520d2d4 fbshipit-source-id: 66e66533cc86d185e7c865376d6a5cdc6520d2d4
This commit is contained in:
committed by
Facebook Github Bot 0
parent
a69b883537
commit
a1ba0918ab
@@ -10,6 +10,8 @@ package com.facebook.react.testing;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
@@ -124,9 +126,21 @@ public class ReactTestHelper {
|
||||
|
||||
@Override
|
||||
public CatalystInstance build() {
|
||||
CatalystInstance instance = builder.build();
|
||||
testCase.initializeWithInstance(instance);
|
||||
instance.runJSBundle();
|
||||
final CatalystInstance instance = builder.build();
|
||||
try {
|
||||
instance.getReactQueueConfiguration().getJSQueueThread().callOnQueue(
|
||||
new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
testCase.initializeWithInstance(instance);
|
||||
instance.runJSBundle();
|
||||
return null;
|
||||
}
|
||||
}).get();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
testCase.waitForBridgeAndUIIdle();
|
||||
return instance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user