Skip to content

Commit f974e52

Browse files
neriousyjonathanmiddleton
authored andcommitted
fix(app): ui flashing when switching tabs (anomalyco#13978)
1 parent 59f9543 commit f974e52

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/app/src/context/global-sdk.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
102102

103103
let attempt: AbortController | undefined
104104
const HEARTBEAT_TIMEOUT_MS = 15_000
105+
let lastEventAt = Date.now()
105106
let heartbeat: ReturnType<typeof setTimeout> | undefined
106107
const resetHeartbeat = () => {
108+
lastEventAt = Date.now()
107109
if (heartbeat) clearTimeout(heartbeat)
108110
heartbeat = setTimeout(() => {
109111
attempt?.abort()
@@ -118,6 +120,7 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
118120
void (async () => {
119121
while (!abort.signal.aborted) {
120122
attempt = new AbortController()
123+
lastEventAt = Date.now()
121124
const onAbort = () => {
122125
attempt?.abort()
123126
}
@@ -182,6 +185,7 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
182185
const onVisibility = () => {
183186
if (typeof document === "undefined") return
184187
if (document.visibilityState !== "visible") return
188+
if (Date.now() - lastEventAt < HEARTBEAT_TIMEOUT_MS) return
185189
attempt?.abort()
186190
}
187191
if (typeof document !== "undefined") {

packages/app/src/context/global-sync/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export async function bootstrapDirectory(input: {
116116
vcsCache: VcsCache
117117
loadSessions: (directory: string) => Promise<void> | void
118118
}) {
119-
input.setStore("status", "loading")
119+
if (input.store.status !== "complete") input.setStore("status", "loading")
120120

121121
const blockingRequests = {
122122
project: () => input.sdk.project.current().then((x) => input.setStore("project", x.data!.id)),

0 commit comments

Comments
 (0)