From 751217c13d0c7d1f2c476107a7b20bc4838f966d Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 8 Aug 2026 00:04:51 +0800 Subject: [PATCH] perf(webui): reduce initial loading delays --- packages/webui/src/App.tsx | 7 +++++-- .../webui/src/hooks/use-onebot-instance-config.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/webui/src/App.tsx b/packages/webui/src/App.tsx index f80865fb..d5d4f207 100644 --- a/packages/webui/src/App.tsx +++ b/packages/webui/src/App.tsx @@ -139,11 +139,14 @@ function AuthBoundary({ onboardingSteps }: { onboardingSteps: AdditionalOnboardi if (ok) { setAuthed(true); setStatus('已连接'); - setMustChange(await client.mustChangePassword()); + const [nextMustChange] = await Promise.all([ + client.mustChangePassword(), + refreshAgreements(), + ]); + setMustChange(nextMustChange); // Carry the URL password into the forced change-password gate so it // needn't re-prompt for the old password (matches the login flow). if (urlPassword) setLoginPassword(urlPassword); - await refreshAgreements(); } setAuthChecked(true); })(); diff --git a/packages/webui/src/hooks/use-onebot-instance-config.ts b/packages/webui/src/hooks/use-onebot-instance-config.ts index 2650f58d..089e1f87 100644 --- a/packages/webui/src/hooks/use-onebot-instance-config.ts +++ b/packages/webui/src/hooks/use-onebot-instance-config.ts @@ -55,7 +55,11 @@ export function useOneBotInstanceConfig( ): UseOneBotInstanceConfig { const api = useApi(); const { runAction } = useActionFeedback(); - const { selectedUin, onSelectedUinChange } = options; + const { onSelectedUinChange } = options; + // Start the first config request in the same render that receives the account + // list; publishing the selection upward remains an effect, but no longer adds + // an otherwise unnecessary render before the network request can begin. + const selectedUin = options.selectedUin ?? accounts[0]?.uin ?? null; const [config, setConfigState] = useState(null); const [loadedUin, setLoadedUin] = useState(null); const [loading, setLoading] = useState(false); @@ -71,10 +75,10 @@ export function useOneBotInstanceConfig( const selectedUinRef = useRef(selectedUin); selectedUinRef.current = selectedUin; - // Auto-select first account when none is selected yet. + // Publish the derived first selection so the sidebar and later routes retain it. useEffect(() => { - if (!selectedUin && accounts.length > 0) onSelectedUinChange(accounts[0].uin); - }, [accounts, selectedUin, onSelectedUinChange]); + if (options.selectedUin === null && selectedUin) onSelectedUinChange(selectedUin); + }, [options.selectedUin, selectedUin, onSelectedUinChange]); // Load on UIN change. The api client already runs normalizeOneBotConfig. useEffect(() => {