Skip to content

Commit bbd1335

Browse files
authored
Use setTimeout-based dispatcher on JS for ReactNative (#2846)
Fixes #2843
1 parent ea440c5 commit bbd1335

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

kotlinx-coroutines-core/js/src/CoroutineContext.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ private const val UNDEFINED = "undefined"
1313
internal external val process: dynamic
1414

1515
internal actual fun createDefaultDispatcher(): CoroutineDispatcher = when {
16-
// Check if we are running under ReactNative. We have to use NodeDispatcher under it.
17-
// The problem is that ReactNative has a `window` object with `addEventListener`, but it does not really work.
18-
// For details see https://github.com/Kotlin/kotlinx.coroutines/issues/236
19-
// The check for ReactNative is based on https://github.com/facebook/react-native/commit/3c65e62183ce05893be0822da217cb803b121c61
20-
jsTypeOf(navigator) != UNDEFINED && navigator != null && navigator.product == "ReactNative" ->
21-
NodeDispatcher
2216
// Check if we are running under jsdom. WindowDispatcher doesn't work under jsdom because it accesses MessageEvent#source.
2317
// It is not implemented in jsdom, see https://github.com/jsdom/jsdom/blob/master/Changelog.md
2418
// "It's missing a few semantics, especially around origins, as well as MessageEvent source."
@@ -27,7 +21,7 @@ internal actual fun createDefaultDispatcher(): CoroutineDispatcher = when {
2721
jsTypeOf(window) != UNDEFINED && window.asDynamic() != null && jsTypeOf(window.asDynamic().addEventListener) != UNDEFINED ->
2822
window.asCoroutineDispatcher()
2923
// If process is undefined (e.g. in NativeScript, #1404), use SetTimeout-based dispatcher
30-
jsTypeOf(process) == UNDEFINED -> SetTimeoutDispatcher
24+
jsTypeOf(process) == UNDEFINED || jsTypeOf(process.nextTick) == UNDEFINED -> SetTimeoutDispatcher
3125
// Fallback to NodeDispatcher when browser environment is not detected
3226
else -> NodeDispatcher
3327
}

0 commit comments

Comments
 (0)