From 974d2b15d5be79d892a62015732cb1ed407fc997 Mon Sep 17 00:00:00 2001 From: Spence Pope Date: Wed, 10 Jun 2026 16:46:35 -0400 Subject: [PATCH] Fix stale push notification replay after account switch (#10792) --- src/Navigation.tsx | 10 ++++++++++ src/lib/hooks/useNotificationHandler.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Navigation.tsx b/src/Navigation.tsx index a83469d27a..1fbd5b1948 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -850,6 +850,8 @@ const LINKING = { }, } satisfies LinkingOptions +let didHandlePushNotificationEntry = false + function RoutesContainer({children}: React.PropsWithChildren<{}>) { const ax = useAnalytics() // eslint-disable-next-line react-compiler/react-compiler @@ -910,6 +912,14 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { function handlePushNotificationEntry() { if (!IS_NATIVE) return + // Only consume a launching notification once per JS runtime. Account + // switches remount the entire tree (see `key={currentAccount?.did}` in + // `App.native.tsx`), which re-fires `onNavigationReady` and would + // otherwise re-process whatever `getLastNotificationResponse` still has + // cached natively (APP-2338). + if (didHandlePushNotificationEntry) return + didHandlePushNotificationEntry = true + // intent urls are handled by `useIntentHandler` if (linkingUrl) return diff --git a/src/lib/hooks/useNotificationHandler.ts b/src/lib/hooks/useNotificationHandler.ts index 65332dea0b..9621cafc88 100644 --- a/src/lib/hooks/useNotificationHandler.ts +++ b/src/lib/hooks/useNotificationHandler.ts @@ -380,6 +380,18 @@ export function useNotificationsHandler() { handleNotification(payload) Notifications.dismissAllNotificationsAsync() + // Also clear the native `lastResponse` cache. Otherwise a subsequent + // `getLastNotificationResponse()` (e.g. on an account-switch remount, + // which re-runs `handlePushNotificationEntry`) would replay this + // payload and ping-pong the user back to the previous account/chat. + try { + Notifications.clearLastNotificationResponse() + } catch (error) { + notyLogger.error( + `useNotificationsHandler: error clearing notification response`, + {error}, + ) + } } else { logger.error('useNotificationsHandler: received no payload', { identifier: e.notification.request.identifier,