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 <noreply@anthropic.com>
This commit is contained in:
parent
a8ad242f88
commit
e5c8761fc9
@ -51,6 +51,7 @@ public final class ClawdbotChatViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var lastHealthPollAt: Date?
|
private var lastHealthPollAt: Date?
|
||||||
|
private var hasInitiallyLoaded = false
|
||||||
|
|
||||||
public init(sessionKey: String, transport: any ClawdbotChatTransport) {
|
public init(sessionKey: String, transport: any ClawdbotChatTransport) {
|
||||||
self.sessionKey = sessionKey
|
self.sessionKey = sessionKey
|
||||||
@ -76,6 +77,7 @@ public final class ClawdbotChatViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func load() {
|
public func load() {
|
||||||
|
guard !self.hasInitiallyLoaded else { return }
|
||||||
Task { await self.bootstrap() }
|
Task { await self.bootstrap() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,6 +176,7 @@ public final class ClawdbotChatViewModel {
|
|||||||
await self.pollHealthIfNeeded(force: true)
|
await self.pollHealthIfNeeded(force: true)
|
||||||
await self.fetchSessions(limit: 50)
|
await self.fetchSessions(limit: 50)
|
||||||
self.errorText = nil
|
self.errorText = nil
|
||||||
|
self.hasInitiallyLoaded = true
|
||||||
} catch {
|
} catch {
|
||||||
self.errorText = error.localizedDescription
|
self.errorText = error.localizedDescription
|
||||||
chatUILogger.error("bootstrap failed \(error.localizedDescription, privacy: .public)")
|
chatUILogger.error("bootstrap failed \(error.localizedDescription, privacy: .public)")
|
||||||
@ -329,6 +332,7 @@ public final class ClawdbotChatViewModel {
|
|||||||
guard !next.isEmpty else { return }
|
guard !next.isEmpty else { return }
|
||||||
guard next != self.sessionKey else { return }
|
guard next != self.sessionKey else { return }
|
||||||
self.sessionKey = next
|
self.sessionKey = next
|
||||||
|
self.hasInitiallyLoaded = false
|
||||||
await self.bootstrap()
|
await self.bootstrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user