π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(boot): one continuous loading screen instead of brand-logo flash on cold start (#15926)
Arvin Xucd9385656105
diff --git a/src/layout/GlobalProvider/CacheHydrationGate.tsx b/src/layout/GlobalProvider/CacheHydrationGate.tsxindex ce7a227b680..28a04fb9eaf 100644--- a/src/layout/GlobalProvider/CacheHydrationGate.tsx+++ b/src/layout/GlobalProvider/CacheHydrationGate.tsx@@ -1,10 +1,8 @@'use client';-import { Center, Flexbox } from '@lobehub/ui';-import { type PropsWithChildren, useEffect, useState } from 'react';+import { type PropsWithChildren, useEffect, useLayoutEffect, useState } from 'react';import { useSyncExternalStore } from 'react';-import { ProductLogo } from '@/components/Branding';import { cacheHydration } from '@/libs/swr/cacheHydration';import { useCacheScope } from '@/libs/swr/useCacheScope';import { useUserStore } from '@/store/user';@@ -12,7 +10,7 @@ import { authSelectors } from '@/store/user/selectors';/*** Max time to wait for the IndexedDB cache tier before rendering anyway, so a- * slow / hung IndexedDB never blocks the app indefinitely.+ * slow / hung IndexedDB (or auth) never blocks the app indefinitely.*/const HYDRATION_TIMEOUT = 1500;@@ -22,9 +20,19 @@ const HYDRATION_TIMEOUT = 1500;* Holds the routed app until the *current identity scope's* IndexedDB cache* tier has hydrated, so local-first data (messages, topics, β¦) is present in* the SWR cache synchronously by the time components mount β including on a- * deep-link cold load. Before auth resolves the scope is `anon:*` (whose- * IndexedDB tier is empty and resolves instantly), so this only ever waits the- * few milliseconds an IndexedDB read takes for the signed-in scope.+ * deep-link cold load.+ *+ * While booting it renders nothing and lets the static HTML `#loading-screen`+ * (a fixed, top-most overlay defined in index.html) stay visible, then removes+ * it in the same layout pass that mounts the children. That keeps the boot a+ * single continuous loading screen β static loader β app β with no second+ * in-React logo and no flash.+ *+ * We deliberately gate through the pre-auth (anon) phase too: before auth+ * resolves the scope is `anon:*`, and un-gating there would paint the app for a+ * frame before auth flips the scope to the signed-in one and re-hydration kicks+ * in β the old `app β logo β app` flicker. Waiting on `isAuthLoaded && ready`+ * collapses that into one uninterrupted loader.*/const CacheHydrationGate = ({ children }: PropsWithChildren) => {const scope = useCacheScope();@@ -36,27 +44,26 @@ const CacheHydrationGate = ({ children }: PropsWithChildren) => {() => true, // SSR: nothing to hydrate);- // Safety valve: never block longer than HYDRATION_TIMEOUT.+ // Safety valve: never block longer than HYDRATION_TIMEOUT, even if auth or+ // IndexedDB hangs. A single boot-level timer (the workspace remount keyed on+ // activeWorkspaceId gives a fresh gate β and timer β when the scope changes).const [timedOut, setTimedOut] = useState(false);useEffect(() => {- if (ready) return;- setTimedOut(false);const timer = setTimeout(() => setTimedOut(true), HYDRATION_TIMEOUT);return () => clearTimeout(timer);- }, [ready, scope]);+ }, []);++ const booting = !(isAuthLoaded && ready) && !timedOut;++ // Hand off from the static loader to the app in one layout pass: children are+ // already committed to the DOM by the time this runs, so removing the loader+ // here (before paint) reveals the app with no intermediate blank/logo frame.+ useLayoutEffect(() => {+ if (booting) return;+ document.getElementById('loading-screen')?.remove();+ }, [booting]);- // Only gate once auth has resolved (so we wait on the real scope, not anon).- // While gating, mirror the boot loading screen (centered brand logo) rather- // than blanking the page, so the hand-off from the static HTML loading screen- // to the routed app stays seamless instead of flashing white.- if (isAuthLoaded && !ready && !timedOut)- return (- <Flexbox height={'100%'} style={{ userSelect: 'none' }} width={'100%'}>- <Center flex={1} gap={16} width={'100%'}>- <ProductLogo size={48} type={'combine'} />- </Center>- </Flexbox>- );+ if (booting) return null;return <>{children}</>;};diff --git a/src/layout/SPAGlobalProvider/index.tsx b/src/layout/SPAGlobalProvider/index.tsxindex 854fdde5620..eddfe46d889 100644--- a/src/layout/SPAGlobalProvider/index.tsx+++ b/src/layout/SPAGlobalProvider/index.tsx@@ -3,7 +3,7 @@import { TooltipGroup } from '@lobehub/ui';import { StyleProvider } from 'antd-style';import { domMax, LazyMotion } from 'motion/react';-import { lazy, memo, type PropsWithChildren, Suspense, useLayoutEffect } from 'react';+import { lazy, memo, type PropsWithChildren, Suspense } from 'react';import { LobeAnalyticsProviderWrapper } from '@/components/Analytics/LobeAnalyticsProviderWrapper';import { DragUploadProvider } from '@/components/DragUploadZone/DragUploadProvider';@@ -35,10 +35,10 @@ const ContextMenuHost = lazy(() =>);const SPAGlobalProvider = memo<PropsWithChildren>(({ children }) => {- useLayoutEffect(() => {- document.getElementById('loading-screen')?.remove();- }, []);-+ // The static HTML #loading-screen is removed by CacheHydrationGate once the+ // SWR cache has hydrated, so the boot stays one continuous loading screen+ // (static loader β app) instead of flashing the loader away before the app+ // and its local-first data are ready.const serverConfig: SPAServerConfig | undefined = window.__SERVER_CONFIG__;const locale = document.documentElement.lang || 'en-US';