From 04fcba893e2418e71fddd99e595780eade43be1a Mon Sep 17 00:00:00 2001 From: Leon Kiefer Date: Thu, 29 Jul 2021 08:51:19 +0200 Subject: [PATCH] fix default dispatcher for react native Fixes #2843 --- kotlinx-coroutines-core/js/src/CoroutineContext.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/kotlinx-coroutines-core/js/src/CoroutineContext.kt b/kotlinx-coroutines-core/js/src/CoroutineContext.kt index e08345a1d2..b1c0c35a49 100644 --- a/kotlinx-coroutines-core/js/src/CoroutineContext.kt +++ b/kotlinx-coroutines-core/js/src/CoroutineContext.kt @@ -13,12 +13,6 @@ private const val UNDEFINED = "undefined" internal external val process: dynamic internal actual fun createDefaultDispatcher(): CoroutineDispatcher = when { - // Check if we are running under ReactNative. We have to use NodeDispatcher under it. - // The problem is that ReactNative has a `window` object with `addEventListener`, but it does not really work. - // For details see https://github.com/Kotlin/kotlinx.coroutines/issues/236 - // The check for ReactNative is based on https://github.com/facebook/react-native/commit/3c65e62183ce05893be0822da217cb803b121c61 - jsTypeOf(navigator) != UNDEFINED && navigator != null && navigator.product == "ReactNative" -> - NodeDispatcher // Check if we are running under jsdom. WindowDispatcher doesn't work under jsdom because it accesses MessageEvent#source. // It is not implemented in jsdom, see https://github.com/jsdom/jsdom/blob/master/Changelog.md // "It's missing a few semantics, especially around origins, as well as MessageEvent source." @@ -27,7 +21,7 @@ internal actual fun createDefaultDispatcher(): CoroutineDispatcher = when { jsTypeOf(window) != UNDEFINED && window.asDynamic() != null && jsTypeOf(window.asDynamic().addEventListener) != UNDEFINED -> window.asCoroutineDispatcher() // If process is undefined (e.g. in NativeScript, #1404), use SetTimeout-based dispatcher - jsTypeOf(process) == UNDEFINED -> SetTimeoutDispatcher + jsTypeOf(process) == UNDEFINED || jsTypeOf(process.nextTick) == UNDEFINED -> SetTimeoutDispatcher // Fallback to NodeDispatcher when browser environment is not detected else -> NodeDispatcher }