From e5c8761fc9fbfe36cf5ac1b2cddb728f8584abee Mon Sep 17 00:00:00 2001 From: Kenny Lee Date: Mon, 26 Jan 2026 16:29:50 -0800 Subject: [PATCH] fix(macos): prevent webchat re-bootstrap on repeated onAppear Add hasInitiallyLoaded flag to guard against calling bootstrap() multiple times when SwiftUI's onAppear fires unexpectedly (layout changes, window show/hide). This prevents the blank loading screen from appearing during normal chat use. Fixes #2465 Co-Authored-By: Claude Opus 4.5 --- .../ClawdbotKit/Sources/ClawdbotChatUI/ChatViewModel.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/shared/ClawdbotKit/Sources/ClawdbotChatUI/ChatViewModel.swift b/apps/shared/ClawdbotKit/Sources/ClawdbotChatUI/ChatViewModel.swift index aa72c8acc..567ef6ada 100644 --- a/apps/shared/ClawdbotKit/Sources/ClawdbotChatUI/ChatViewModel.swift +++ b/apps/shared/ClawdbotKit/Sources/ClawdbotChatUI/ChatViewModel.swift @@ -51,6 +51,7 @@ public final class ClawdbotChatViewModel { } private var lastHealthPollAt: Date? + private var hasInitiallyLoaded = false public init(sessionKey: String, transport: any ClawdbotChatTransport) { self.sessionKey = sessionKey @@ -76,6 +77,7 @@ public final class ClawdbotChatViewModel { } public func load() { + guard !self.hasInitiallyLoaded else { return } Task { await self.bootstrap() } } @@ -174,6 +176,7 @@ public final class ClawdbotChatViewModel { await self.pollHealthIfNeeded(force: true) await self.fetchSessions(limit: 50) self.errorText = nil + self.hasInitiallyLoaded = true } catch { self.errorText = error.localizedDescription chatUILogger.error("bootstrap failed \(error.localizedDescription, privacy: .public)") @@ -329,6 +332,7 @@ public final class ClawdbotChatViewModel { guard !next.isEmpty else { return } guard next != self.sessionKey else { return } self.sessionKey = next + self.hasInitiallyLoaded = false await self.bootstrap() }