From fc8fafbdf5e01edc487192393293b944e77f5920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Liberata=20Torres?= <47488813+MaximoLiberata@users.noreply.github.com> Date: Wed, 10 Apr 2024 10:39:22 -0400 Subject: [PATCH] fix(react-native): error Cannot create URL for blob (#1840) * [Bug]: Error Cannot create URL for blob in React Native * Change RN conditional logic * Make conventional eslint styles --- src/lib/BufferedDuplex.ts | 1 + src/lib/get-timer.ts | 6 ++++-- src/lib/is-browser.ts | 2 ++ src/lib/shared.ts | 11 ++++++----- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/lib/BufferedDuplex.ts b/src/lib/BufferedDuplex.ts index 520f9142f..99af4bb37 100644 --- a/src/lib/BufferedDuplex.ts +++ b/src/lib/BufferedDuplex.ts @@ -1,4 +1,5 @@ import { Duplex, Transform } from 'readable-stream' +import { Buffer } from 'buffer' import { IClientOptions } from './client' /** diff --git a/src/lib/get-timer.ts b/src/lib/get-timer.ts index d1d927ed1..1ae216a7a 100644 --- a/src/lib/get-timer.ts +++ b/src/lib/get-timer.ts @@ -1,4 +1,4 @@ -import isBrowser, { isWebWorker } from './is-browser' +import isBrowser, { isWebWorker, isReactNativeBrowser } from './is-browser' import { clearTimeout as clearT, setTimeout as setT } from 'worker-timers' import type { TimerVariant } from './shared' @@ -30,7 +30,9 @@ const getTimer = (variant: TimerVariant): Timer => { } case 'auto': default: { - return isBrowser && !isWebWorker ? workerTimer : nativeTimer + return isBrowser && !isWebWorker && !isReactNativeBrowser + ? workerTimer + : nativeTimer } } } diff --git a/src/lib/is-browser.ts b/src/lib/is-browser.ts index 2c11dac91..02134ab8f 100644 --- a/src/lib/is-browser.ts +++ b/src/lib/is-browser.ts @@ -17,4 +17,6 @@ const isBrowser = export const isWebWorker = isWebWorkerEnv() +export const isReactNativeBrowser = isReactNativeEnv() + export default isBrowser diff --git a/src/lib/shared.ts b/src/lib/shared.ts index bdbee8c43..1fb16c7b5 100644 --- a/src/lib/shared.ts +++ b/src/lib/shared.ts @@ -76,8 +76,9 @@ export function applyMixin( } } } -export const nextTick = process - ? process.nextTick - : (callback: () => void) => { - setTimeout(callback, 0) - } +export const nextTick = + typeof process?.nextTick === 'function' + ? process.nextTick + : (callback: () => void) => { + setTimeout(callback, 0) + }