From c0fc3b54689fc1ea6d51146c2cae8cbb5e9b9ca1 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 21 Sep 2026 17:40:58 -0500 Subject: [PATCH] Read device ID directly in analytics context (#11742) --- src/analytics/identifiers/device.ts | 21 --------------------- src/analytics/index.tsx | 3 +-- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/analytics/identifiers/device.ts b/src/analytics/identifiers/device.ts index 3d9254483..ac5014354 100644 --- a/src/analytics/identifiers/device.ts +++ b/src/analytics/identifiers/device.ts @@ -1,4 +1,3 @@ -import {useSyncExternalStore} from 'react' import uuid from 'react-native-uuid' import AsyncStorage from '@react-native-async-storage/async-storage' @@ -25,23 +24,3 @@ export function getDeviceIdOrThrow() { } return id } - -function subscribeToDeviceId(onChange: () => void) { - const sub = device.addOnValueChangedListener(['deviceId'], onChange) - return () => sub.remove() -} - -/** - * Reads the device ID for use during render. The app awaits - * `getAndMigrateDeviceId` before booting (see `setupDeviceId` in - * `analytics/index.tsx`), so this is normally set on first read. - * - * Subscribing rather than reading storage directly means a late write - a - * caller that mounts before the migration resolves - still propagates, instead - * of leaving consumers pinned to `undefined` for the lifetime of the component. - * `useSyncExternalStore` re-evaluates the snapshot every render, so there's no - * gap between the initial read and the subscription. - */ -export function useDeviceId() { - return useSyncExternalStore(subscribeToDeviceId, getDeviceId) -} diff --git a/src/analytics/index.tsx b/src/analytics/index.tsx index ac1c96e62..07f82b4b2 100644 --- a/src/analytics/index.tsx +++ b/src/analytics/index.tsx @@ -20,7 +20,6 @@ import { getAndMigrateDeviceId, getDeviceId, getInitialSessionId, - useDeviceId, useSessionId, } from '#/analytics/identifiers' import { @@ -180,7 +179,7 @@ export function AnalyticsContext({ ) } } - const deviceId = useDeviceId() ?? 'unknown' + const deviceId = getDeviceId() ?? 'unknown' const sessionId = useSessionId() // only IP based, never GPS const geolocation = useGeolocationServiceResponse() -- knotmirror 0.0.1