fix(mobile): Recover thread state reliably after reconnects #4034
Closedjuliusmarmingewants to merge 4 commits into
t3code/audit-mobile-thread-sync fromrefs/pull/4034/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -147,0 +201,21 @@201+ const delayMs =202+ THREAD_DETAIL_STALL_RETRY_DELAYS_MS[attempts] ?? THREAD_DETAIL_STALL_ERROR_DELAY_MS;203+ timer = setTimeout(() => {204+ if (cancelled) {205+ return;206+ }207+ const currentAttempts = detailRefreshAttemptsRef.current.get(routeThreadKey) ?? 0;208+ if (currentAttempts !== attempts) {209+ return;210+ }211+ if (attempts >= THREAD_DETAIL_STALL_RETRY_DELAYS_MS.length) {212+ setStalledDetailKey(routeThreadKey);213+ return;214+ }215+ detailRefreshAttemptsRef.current.set(routeThreadKey, attempts + 1);216+ refreshSelectedThreadDetailRef.current();217+ scheduleRetry();218+ }, delayMs);219+ };220+221+ scheduleRetry();
- apps/mobile/src/features/threads/ThreadRouteScreen.tsx line 189OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -147,0 +169,21 @@169+ [routeThreadKey],170+ );171+172+ useEffect(() => {173+ if (routeThreadKey === null) {174+ return;175+ }176+177+ if (selectedThreadKey !== routeThreadKey) {178+ return;179+ }180+181+ if (selectedThreadDetail !== null || selectedThreadDetailState.status === "deleted") {182+ detailRefreshAttemptsRef.current.delete(routeThreadKey);183+ setStalledDetailKey((current) => (current === routeThreadKey ? null : current));184+ return;185+ }186+187+ // A warm reconnect legitimately has no detail while the runtime catches188+ // up. The watchdog should start only after synchronization settles.189+ if (selectedThreadDetailState.status === "synchronizing") {
- @@ -147,0 +173,21 @@173+ if (routeThreadKey === null) {174+ return;175+ }176+177+ if (selectedThreadKey !== routeThreadKey) {178+ return;179+ }180+181+ if (selectedThreadDetail !== null || selectedThreadDetailState.status === "deleted") {182+ detailRefreshAttemptsRef.current.delete(routeThreadKey);183+ setStalledDetailKey((current) => (current === routeThreadKey ? null : current));184+ return;185+ }186+187+ // A warm reconnect legitimately has no detail while the runtime catches188+ // up. The watchdog should start only after synchronization settles.189+ if (selectedThreadDetailState.status === "synchronizing") {190+ detailRefreshAttemptsRef.current.delete(routeThreadKey);191+ setStalledDetailKey((current) => (current === routeThreadKey ? null : current));192+ return;193+ }
- @@ -147,0 +175,21 @@175+ }176+177+ if (selectedThreadKey !== routeThreadKey) {178+ return;179+ }180+181+ if (selectedThreadDetail !== null || selectedThreadDetailState.status === "deleted") {182+ detailRefreshAttemptsRef.current.delete(routeThreadKey);183+ setStalledDetailKey((current) => (current === routeThreadKey ? null : current));184+ return;185+ }186+187+ if (routeConnectionState !== "connected") {188+ detailRefreshAttemptsRef.current.delete(routeThreadKey);189+ setStalledDetailKey((current) => (current === routeThreadKey ? null : current));190+ return;191+ }192+193+ if (stalledDetailKey === routeThreadKey) {194+ return;195+ }
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
9e832643-4f74-4f60-a2cf-63faef79e6cbYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.