From 121ba4adbd119c7e864309374e80314d76744376 Mon Sep 17 00:00:00 2001 From: tris203 Date: Mon, 23 Nov 2026 22:34:46 +0000 Subject: [PATCH] fix(mobile): T3 Connect sign-in recovers after launching offline --- .../src/features/cloud/CloudAuthProvider.tsx | 15 ++++++++++++--- .../src/relay/cloudAccountService.test.ts | 4 +++- .../src/relay/cloudAccountService.ts | 8 +++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/mobile/src/features/cloud/CloudAuthProvider.tsx b/apps/mobile/src/features/cloud/CloudAuthProvider.tsx index df20ef805cd1d..1e6297486b806 100644 --- a/apps/mobile/src/features/cloud/CloudAuthProvider.tsx +++ b/apps/mobile/src/features/cloud/CloudAuthProvider.tsx @@ -1,4 +1,5 @@ import { ClerkProvider, getClerkInstance } from "@clerk/expo"; +import { resourceCache } from "@clerk/expo/resource-cache"; import { tokenCache } from "@clerk/expo/token-cache"; import type { ReactNode } from "react"; @@ -11,8 +12,12 @@ const publishableKey = cloudConfig.relay.url ? cloudConfig.clerk.publishableKey if (publishableKey) { // The same native singleton ClerkProvider renders with, so the service - // observes it for the app's lifetime without a React subscription. - cloudAccountService.attach(getClerkInstance({ publishableKey })); + // observes it for the app's lifetime without a React subscription. Clerk + // reads the resource cache only when this creates the singleton; without + // it, a launch load that fails offline is never retried. + cloudAccountService.attach( + getClerkInstance({ publishableKey, __experimental_resourceCache: resourceCache }), + ); } else { // Without cloud config no account can ever activate, so drop anything a // previous build with cloud enabled left registered. @@ -25,7 +30,11 @@ export function CloudAuthProvider(props: { readonly children: ReactNode }) { } return ( - + {props.children} ); diff --git a/packages/client-runtime/src/relay/cloudAccountService.test.ts b/packages/client-runtime/src/relay/cloudAccountService.test.ts index 1549f9e4f6a62..4b34a5678d9da 100644 --- a/packages/client-runtime/src/relay/cloudAccountService.test.ts +++ b/packages/client-runtime/src/relay/cloudAccountService.test.ts @@ -160,9 +160,11 @@ describe("createCloudAccountService", () => { const { source, emit } = makeSource(); service.attach(source); - // Offline: an id-less client, or the placeholder built from the session cookie. + // Offline: an id-less client, the placeholder built from the session cookie, + // or the placeholder Expo's empty resource cache loads. emit(null, ""); emit(null, "client_init"); + emit(null, "client_DUMMY_ID"); expect(service.getState()).toEqual({ _tag: "Unobserved" }); expect(log).toEqual([]); diff --git a/packages/client-runtime/src/relay/cloudAccountService.ts b/packages/client-runtime/src/relay/cloudAccountService.ts index 7f885281d3b90..53221a78c144d 100644 --- a/packages/client-runtime/src/relay/cloudAccountService.ts +++ b/packages/client-runtime/src/relay/cloudAccountService.ts @@ -16,12 +16,14 @@ export interface CloudAccountSource { /** * Clerk's load status cannot prove its API answered: offline it emits an - * id-less client, and a failed launch fetch emits a "client_init" placeholder - * built from the session cookie. Only a real /v1/client response has an id. + * id-less client, a failed launch fetch emits a "client_init" placeholder + * built from the session cookie, and Expo's resource cache starts empty with a + * "client_DUMMY_ID" placeholder. Only a real /v1/client response has an id. */ +const PLACEHOLDER_CLIENT_IDS = new Set(["client_init", "client_DUMMY_ID"]); const isClientFromClerkApi = ( client: { readonly id?: string | null | undefined } | null | undefined, -) => Boolean(client?.id) && client?.id !== "client_init"; +) => Boolean(client?.id) && !PLACEHOLDER_CLIENT_IDS.has(client?.id ?? ""); interface CloudAccountSignIn { readonly _tag: "SignIn";