From 5213457b6b5285349094ed9ed8b6bd1f5f152237 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Wed, 30 Oct 2024 13:57:19 +0100 Subject: [PATCH 1/3] fix: avoid startTransition in React Native --- src/FlagProvider.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/FlagProvider.tsx b/src/FlagProvider.tsx index 3e5a742..f570472 100644 --- a/src/FlagProvider.tsx +++ b/src/FlagProvider.tsx @@ -23,7 +23,11 @@ const offlineConfig: IConfig = { // save startTransition as var to avoid webpack analysis (https://github.com/webpack/webpack/issues/14814) const _startTransition = 'startTransition'; // fallback for React <18 which doesn't support startTransition -const startTransition = React[_startTransition] || (fn => fn()); +const isReactNative = typeof navigator !== 'undefined' && navigator?.product === 'ReactNative'; +// Fallback for React <18 and exclude startTransition if in React Native +const startTransition: (fn: () => void) => void = !isReactNative && React[_startTransition] + ? React[_startTransition] + : (fn => fn()); const FlagProvider: FC> = ({ config: customConfig, From a5030456c0109f6e5751f0a0dd406c2d3cde12ee Mon Sep 17 00:00:00 2001 From: kwasniew Date: Thu, 31 Oct 2024 13:30:17 +0100 Subject: [PATCH 2/3] expose state transition on provided --- src/FlagProvider.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/FlagProvider.tsx b/src/FlagProvider.tsx index f570472..5354ad6 100644 --- a/src/FlagProvider.tsx +++ b/src/FlagProvider.tsx @@ -9,6 +9,7 @@ export interface IFlagProvider { unleashClient?: UnleashClient; startClient?: boolean; stopClient?: boolean; + startTransition?: (fn: () => void) => void; } const offlineConfig: IConfig = { @@ -23,9 +24,8 @@ const offlineConfig: IConfig = { // save startTransition as var to avoid webpack analysis (https://github.com/webpack/webpack/issues/14814) const _startTransition = 'startTransition'; // fallback for React <18 which doesn't support startTransition -const isReactNative = typeof navigator !== 'undefined' && navigator?.product === 'ReactNative'; // Fallback for React <18 and exclude startTransition if in React Native -const startTransition: (fn: () => void) => void = !isReactNative && React[_startTransition] +const defaultStartTransition: (fn: () => void) => void = React[_startTransition] ? React[_startTransition] : (fn => fn()); @@ -35,6 +35,7 @@ const FlagProvider: FC> = ({ unleashClient, startClient = true, stopClient = true, + startTransition = defaultStartTransition }) => { const config = customConfig || offlineConfig; const client = React.useRef( From 4a336f23f58269ae7c7bb2823589d682d217473c Mon Sep 17 00:00:00 2001 From: kwasniew Date: Thu, 31 Oct 2024 13:30:57 +0100 Subject: [PATCH 3/3] expose state transition on provided --- src/FlagProvider.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/FlagProvider.tsx b/src/FlagProvider.tsx index 5354ad6..de05c05 100644 --- a/src/FlagProvider.tsx +++ b/src/FlagProvider.tsx @@ -25,9 +25,7 @@ const offlineConfig: IConfig = { const _startTransition = 'startTransition'; // fallback for React <18 which doesn't support startTransition // Fallback for React <18 and exclude startTransition if in React Native -const defaultStartTransition: (fn: () => void) => void = React[_startTransition] - ? React[_startTransition] - : (fn => fn()); +const defaultStartTransition = React[_startTransition] || (fn => fn()); const FlagProvider: FC> = ({ config: customConfig,