Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-query-client-rn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/expo": patch
---

Fix `useOrganizationList` and other query-based hooks returning empty data on React Native by synchronously providing a `QueryClient` instance
20 changes: 20 additions & 0 deletions packages/expo/src/provider/singleton/createClerkInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@
const saveToken = tokenCache.saveToken;
__internal_clerk = new ClerkClass(publishableKey) as unknown as BrowserClerk;

// The clerk-js native bundle uses rspack code-splitting for the internal QueryClient.
// On React Native, rspack's chunk loading doesn't work (Metro bundles into a single file),
// so the dynamic import never resolves and __internal_queryClient stays undefined.
// This breaks hooks that depend on the query client (useOrganizationList, etc.).
// Override the getter to synchronously create a QueryClient on first access.
{
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const { QueryClient } = require('@tanstack/query-core');
let queryClient: InstanceType<typeof QueryClient> | undefined;

Check warning on line 74 in packages/expo/src/provider/singleton/createClerkInstance.ts

View workflow job for this annotation

GitHub Actions / Static analysis

'any' overrides all other types in this union type
Object.defineProperty(__internal_clerk, '__internal_queryClient', {
get() {
if (!queryClient) {
queryClient = new QueryClient();
}
return { __tag: 'clerk-rq-client', client: queryClient };
},
configurable: true,
});
}

if (Platform.OS === 'ios' || Platform.OS === 'android') {
// @ts-expect-error - This is an internal API
__internal_clerk.__internal_createPublicCredentials = (
Expand Down
Loading