Skip to content

Commit 6e42996

Browse files
committed
fix(expo): gate all console calls behind __DEV__ flag
Wrap all runtime console.log/warn/error calls in the expo package with __DEV__ guards so they are stripped from production builds.
1 parent 246f4aa commit 6e42996

7 files changed

Lines changed: 34 additions & 19 deletions

File tree

packages/expo/src/cache/ResourceCache.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ function createResourceCache<T>(key: string): ResourceCache<T> {
3535
const value = await storage!.get(itemKey!);
3636
return value ? JSON.parse(value) : null;
3737
} catch (error) {
38-
console.log(`Clerk: Error loading value on ${key} from storage:`, error);
38+
if (__DEV__) {
39+
console.error(`Clerk: Error loading value on ${key} from storage:`, error);
40+
}
3941
return null;
4042
}
4143
};
@@ -46,7 +48,9 @@ function createResourceCache<T>(key: string): ResourceCache<T> {
4648
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4749
return await storage!.set(itemKey!, JSON.stringify(value));
4850
} catch (error) {
49-
console.log(`Clerk: Error saving value on ${key} in storage:`, error);
51+
if (__DEV__) {
52+
console.error(`Clerk: Error saving value on ${key} in storage:`, error);
53+
}
5054
}
5155
};
5256

@@ -56,7 +60,9 @@ function createResourceCache<T>(key: string): ResourceCache<T> {
5660
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
5761
return await storage!.set(itemKey!, '');
5862
} catch (error) {
59-
console.log(`Clerk: Error deleting value on ${key} from storage:`, error);
63+
if (__DEV__) {
64+
console.error(`Clerk: Error deleting value on ${key} from storage:`, error);
65+
}
6066
}
6167
};
6268

packages/expo/src/hooks/useNativeAuthEvents.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,28 @@ export function useNativeAuthEvents(): UseNativeAuthEventsReturn {
7171
const [nativeAuthState, setNativeAuthState] = useState<NativeAuthStateEvent | null>(null);
7272

7373
useEffect(() => {
74-
console.log(`[useNativeAuthEvents] INIT: isNativeSupported=${isNativeSupported}, ClerkExpo=${!!ClerkExpo}`);
75-
7674
if (!isNativeSupported || !ClerkExpo) {
77-
console.log(`[useNativeAuthEvents] SKIP: Native not supported or ClerkExpo not available`);
7875
return;
7976
}
8077

8178
let subscription: { remove: () => void } | null = null;
8279

8380
try {
84-
console.log(`[useNativeAuthEvents] SETUP: Creating NativeEventEmitter for ClerkExpo`);
8581
const eventEmitter = new NativeEventEmitter(ClerkExpo as any);
8682

87-
console.log(`[useNativeAuthEvents] LISTEN: Adding listener for 'onAuthStateChange' events`);
8883
subscription = eventEmitter.addListener('onAuthStateChange', (event: NativeAuthStateEvent) => {
89-
console.log('[useNativeAuthEvents] EVENT_RECEIVED:', JSON.stringify(event));
84+
if (__DEV__) {
85+
console.log('[useNativeAuthEvents] onAuthStateChange:', JSON.stringify(event));
86+
}
9087
setNativeAuthState(event);
9188
});
92-
console.log(`[useNativeAuthEvents] LISTEN: Listener added successfully`);
9389
} catch (error) {
94-
console.log('[useNativeAuthEvents] ERROR: Could not set up event listener:', error);
90+
if (__DEV__) {
91+
console.error('[useNativeAuthEvents] Failed to set up event listener:', error);
92+
}
9593
}
9694

9795
return () => {
98-
console.log(`[useNativeAuthEvents] CLEANUP: Removing event listener`);
9996
subscription?.remove();
10097
};
10198
}, []);

packages/expo/src/hooks/useNativeSession.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ export function useNativeSession(): UseNativeSessionReturn {
117117
setSessionId(id);
118118
setUser(result?.user ?? null);
119119
} catch (error) {
120-
console.log('[useNativeSession] Error fetching native session:', error);
120+
if (__DEV__) {
121+
console.error('[useNativeSession] Error fetching native session:', error);
122+
}
121123
setSessionId(null);
122124
setUser(null);
123125
} finally {

packages/expo/src/native/InlineUserProfileView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export function InlineUserProfileView({ isDismissable = false, style }: InlineUs
7878
try {
7979
await clerk.signOut();
8080
} catch (err) {
81-
console.warn('[InlineUserProfileView] JS SDK sign out error:', err);
81+
if (__DEV__) {
82+
console.warn('[InlineUserProfileView] JS SDK sign out error:', err);
83+
}
8284
}
8385
}
8486
}

packages/expo/src/native/UserButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ export function UserButton(_props: UserButtonProps) {
104104
setNativeUser(null);
105105
}
106106
} catch (err) {
107-
console.error('[UserButton] Error fetching user:', err);
107+
if (__DEV__) {
108+
console.error('[UserButton] Error fetching user:', err);
109+
}
108110
}
109111
};
110112

packages/expo/src/native/UserProfileView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export function UserProfileView({ isDismissable = false, style }: UserProfileVie
9090
try {
9191
await clerk.signOut();
9292
} catch (err) {
93-
console.warn('[UserProfileView] JS SDK sign out error:', err);
93+
if (__DEV__) {
94+
console.warn('[UserProfileView] JS SDK sign out error:', err);
95+
}
9496
}
9597
}
9698
}

packages/expo/src/provider/ClerkProvider.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ export function ClerkProvider<TUi extends Ui = Ui>(props: ClerkProviderProps<TUi
183183
try {
184184
await clerkInstance.setActive({ session: pendingSession });
185185
} catch (err) {
186-
console.error(`[ClerkProvider] Failed to sync native session:`, err);
186+
if (__DEV__) {
187+
console.error(`[ClerkProvider] Failed to sync native session:`, err);
188+
}
187189
}
188190
}
189191
}
@@ -200,7 +202,7 @@ export function ClerkProvider<TUi extends Ui = Ui>(props: ClerkProviderProps<TUi
200202
`To enable native features, add "@clerk/expo" to your app.json plugins array.`,
201203
);
202204
}
203-
} else {
205+
} else if (__DEV__) {
204206
console.error(`[ClerkProvider] Failed to configure Clerk ${Platform.OS}:`, error);
205207
}
206208
}
@@ -249,7 +251,9 @@ export function ClerkProvider<TUi extends Ui = Ui>(props: ClerkProviderProps<TUi
249251
await clerkInstance.signOut();
250252
}
251253
} catch (error) {
252-
console.error(`[ClerkProvider] Failed to sync native auth state:`, error);
254+
if (__DEV__) {
255+
console.error(`[ClerkProvider] Failed to sync native auth state:`, error);
256+
}
253257
}
254258
};
255259

0 commit comments

Comments
 (0)