44 useEffect ,
55 type PropsWithChildren ,
66} from 'react' ;
7+ import { Platform } from 'react-native' ;
78import type { Config , DetourContextType } from './links/types' ;
89import { analyticsEmitter } from './analytics/utils/analyticsEmitter' ;
910import { sendEvent } from './analytics/api/events' ;
@@ -19,8 +20,15 @@ type Props = PropsWithChildren & { config: Config };
1920const DetourContext = createContext < DetourContextType | undefined > ( undefined ) ;
2021
2122let activeProviderCount = 0 ;
23+ let hasWarnedUnsupportedWeb = false ;
2224
23- export const DetourProvider = ( { config, children } : Props ) => {
25+ const NOOP_DETOUR_CONTEXT : DetourContextType = {
26+ isLinkProcessed : true ,
27+ link : null ,
28+ clearLink : ( ) => { } ,
29+ } ;
30+
31+ const DetourProviderNative = ( { config, children } : Props ) => {
2432 const {
2533 apiKey,
2634 appID,
@@ -93,6 +101,28 @@ export const DetourProvider = ({ config, children }: Props) => {
93101 ) ;
94102} ;
95103
104+ export const DetourProvider = ( { config, children } : Props ) => {
105+ if ( Platform . OS === 'web' ) {
106+ if ( __DEV__ && ! hasWarnedUnsupportedWeb ) {
107+ console . warn (
108+ '🔗[Detour:WEB_UNSUPPORTED] DetourProvider is disabled on Expo Web. ' +
109+ 'SDK initialization is skipped on web and no links will be processed.'
110+ ) ;
111+ hasWarnedUnsupportedWeb = true ;
112+ }
113+
114+ return (
115+ < DetourContext . Provider value = { NOOP_DETOUR_CONTEXT } >
116+ { children }
117+ </ DetourContext . Provider >
118+ ) ;
119+ }
120+
121+ return (
122+ < DetourProviderNative config = { config } > { children } </ DetourProviderNative >
123+ ) ;
124+ } ;
125+
96126export const useDetourContext = ( ) => {
97127 const context = useContext ( DetourContext ) ;
98128
0 commit comments