@@ -26,10 +26,14 @@ import { ReflagContext, ReflagDeprecatedContext } from "./context";
2626import { HookArgs , HooksManager , State } from "./hooksManager" ;
2727import { HttpClient } from "./httpClient" ;
2828import { Logger , loggerWithPrefix , quietConsoleLogger } from "./logger" ;
29+ import { StorageAdapter } from "./storage" ;
2930import { showToolbarToggle } from "./toolbar" ;
3031
3132const isMobile = typeof window !== "undefined" && window . innerWidth < 768 ;
3233const isNode = typeof document === "undefined" ; // deno supports "window" but not "document" according to https://remix.run/docs/en/main/guides/gotchas
34+ const isReactNative =
35+ typeof navigator !== "undefined" &&
36+ / R e a c t N a t i v e / i. test ( navigator . userAgent ?? "" ) ;
3337
3438/**
3539 * (Internal) User context.
@@ -297,6 +301,12 @@ export type InitOptions = ReflagDeprecatedContext & {
297301 * Pre-fetched flags to be used instead of fetching them from the server.
298302 */
299303 bootstrappedFlags ?: RawFlags ;
304+
305+ /**
306+ * Optional storage adapter used for caching flags and overrides.
307+ * Useful for React Native (AsyncStorage).
308+ */
309+ storage ?: StorageAdapter ;
300310} ;
301311
302312const defaultConfig : Config = {
@@ -366,7 +376,9 @@ export interface Flag {
366376
367377function shouldShowToolbar ( opts : InitOptions ) {
368378 const toolbarOpts = opts . toolbar ;
369- if ( typeof window === "undefined" ) return false ;
379+ if ( typeof window === "undefined" || typeof window . location === "undefined" ) {
380+ return false ;
381+ }
370382 if ( typeof toolbarOpts === "boolean" ) return toolbarOpts ;
371383 if ( typeof toolbarOpts ?. show === "boolean" ) return toolbarOpts . show ;
372384 return window . location . hostname === "localhost" ;
@@ -439,13 +451,15 @@ export class ReflagClient {
439451 timeoutMs : opts . timeoutMs ,
440452 fallbackFlags : opts . fallbackFlags ,
441453 offline : this . config . offline ,
454+ storage : opts . storage ,
442455 } ,
443456 ) ;
444457
445458 if (
446459 ! this . config . offline &&
447460 this . context ?. user &&
448461 ! isNode && // do not prompt on server-side
462+ ! isReactNative && // disable SSE-based auto feedback in React Native
449463 opts ?. feedback ?. enableAutoFeedback !== false // default to on
450464 ) {
451465 if ( isMobile ) {
@@ -870,6 +884,13 @@ export class ReflagClient {
870884 return this . flagsClient . getFlags ( ) ;
871885 }
872886
887+ /**
888+ * Force refresh flags from the API, bypassing cache.
889+ */
890+ refresh ( ) {
891+ return this . flagsClient . refreshFlags ( ) ;
892+ }
893+
873894 /**
874895 * @deprecated Use `getFlag` instead.
875896 */
0 commit comments