Skip to content

Commit 30e90e5

Browse files
committed
fix(clerk-js): resolve offline mode crash by enhancing error handling and cache fallback
1 parent ffd4ab0 commit 30e90e5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/clerk-expo': patch
4+
---
5+
6+
Fix offline mode crash when using `__experimental_resourceCache` by handling missing `protect_config` field from FAPI response and broadening error handling to trigger cache fallback for non-network errors.

packages/clerk-js/src/core/clerk.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,8 +2741,7 @@ export class Clerk implements ClerkInterface {
27412741
};
27422742

27432743
private shouldFallbackToCachedResources = (): boolean => {
2744-
const hasCacheFunction = !!this.__internal_getCachedResources;
2745-
return hasCacheFunction;
2744+
return !!this.__internal_getCachedResources;
27462745
};
27472746

27482747
#loadInNonStandardBrowser = async (): Promise<void> => {
@@ -2755,9 +2754,11 @@ export class Clerk implements ClerkInterface {
27552754
Client.getOrCreateInstance().fetch({ fetchMaxTries }),
27562755
]);
27572756
} catch (err) {
2758-
const shouldFallback =
2759-
this.shouldFallbackToCachedResources() &&
2760-
((isClerkRuntimeError(err) && err.code === 'network_error') || !isClerkRuntimeError(err));
2757+
const isNetworkError =
2758+
(isClerkRuntimeError(err) && err.code === 'network_error') ||
2759+
(err instanceof Error && err.message?.includes('Network error at'));
2760+
2761+
const shouldFallback = this.shouldFallbackToCachedResources() && isNetworkError;
27612762

27622763
if (shouldFallback) {
27632764
const cachedResources = await this.__internal_getCachedResources?.();

0 commit comments

Comments
 (0)