Просмотр исходного кода

fix(app): ui flashing when switching tabs (#13978)

Filip 1 месяц назад
Родитель
Сommit
46739ca7cd

+ 4 - 0
packages/app/src/context/global-sdk.tsx

@@ -102,8 +102,10 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
 
     let attempt: AbortController | undefined
     const HEARTBEAT_TIMEOUT_MS = 15_000
+    let lastEventAt = Date.now()
     let heartbeat: ReturnType<typeof setTimeout> | undefined
     const resetHeartbeat = () => {
+      lastEventAt = Date.now()
       if (heartbeat) clearTimeout(heartbeat)
       heartbeat = setTimeout(() => {
         attempt?.abort()
@@ -118,6 +120,7 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
     void (async () => {
       while (!abort.signal.aborted) {
         attempt = new AbortController()
+        lastEventAt = Date.now()
         const onAbort = () => {
           attempt?.abort()
         }
@@ -182,6 +185,7 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
     const onVisibility = () => {
       if (typeof document === "undefined") return
       if (document.visibilityState !== "visible") return
+      if (Date.now() - lastEventAt < HEARTBEAT_TIMEOUT_MS) return
       attempt?.abort()
     }
     if (typeof document !== "undefined") {

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

@@ -116,7 +116,7 @@ export async function bootstrapDirectory(input: {
   vcsCache: VcsCache
   loadSessions: (directory: string) => Promise<void> | void
 }) {
-  input.setStore("status", "loading")
+  if (input.store.status !== "complete") input.setStore("status", "loading")
 
   const blockingRequests = {
     project: () => input.sdk.project.current().then((x) => input.setStore("project", x.data!.id)),