Skip to content

Commit 5214432

Browse files
authored
feat: disable detour provider on web (#41)
1 parent 4acfc1a commit 5214432

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

src/DetourContext.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useEffect,
55
type PropsWithChildren,
66
} from 'react';
7+
import { Platform } from 'react-native';
78
import type { Config, DetourContextType } from './links/types';
89
import { analyticsEmitter } from './analytics/utils/analyticsEmitter';
910
import { sendEvent } from './analytics/api/events';
@@ -19,8 +20,15 @@ type Props = PropsWithChildren & { config: Config };
1920
const DetourContext = createContext<DetourContextType | undefined>(undefined);
2021

2122
let 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+
96126
export const useDetourContext = () => {
97127
const context = useContext(DetourContext);
98128

0 commit comments

Comments
 (0)