Skip to content

fix: avoid startTransition in React Native #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/FlagProvider.tsx
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ export interface IFlagProvider {
unleashClient?: UnleashClient;
startClient?: boolean;
stopClient?: boolean;
startTransition?: (fn: () => void) => void;
}

const offlineConfig: IConfig = {
@@ -23,14 +24,16 @@ 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());
// Fallback for React <18 and exclude startTransition if in React Native
const defaultStartTransition = React[_startTransition] || (fn => fn());

const FlagProvider: FC<PropsWithChildren<IFlagProvider>> = ({
config: customConfig,
children,
unleashClient,
startClient = true,
stopClient = true,
startTransition = defaultStartTransition
}) => {
const config = customConfig || offlineConfig;
const client = React.useRef<UnleashClient>(