perf(webui): reduce initial loading delays
This commit is contained in:
2 files changed
+13
-6
No files matched your search
@@ -139,11 +139,14 @@ function AuthBoundary({ onboardingSteps }: { onboardingSteps: AdditionalOnboardi
|
|||||||
if (ok) {
|
if (ok) {
|
||||||
setAuthed(true);
|
setAuthed(true);
|
||||||
setStatus('已连接');
|
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
|
// Carry the URL password into the forced change-password gate so it
|
||||||
// needn't re-prompt for the old password (matches the login flow).
|
// needn't re-prompt for the old password (matches the login flow).
|
||||||
if (urlPassword) setLoginPassword(urlPassword);
|
if (urlPassword) setLoginPassword(urlPassword);
|
||||||
await refreshAgreements();
|
|
||||||
}
|
}
|
||||||
setAuthChecked(true);
|
setAuthChecked(true);
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -55,7 +55,11 @@ export function useOneBotInstanceConfig(
|
|||||||
): UseOneBotInstanceConfig {
|
): UseOneBotInstanceConfig {
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const { runAction } = useActionFeedback();
|
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<OneBotConfig | null>(null);
|
const [config, setConfigState] = useState<OneBotConfig | null>(null);
|
||||||
const [loadedUin, setLoadedUin] = useState<string | null>(null);
|
const [loadedUin, setLoadedUin] = useState<string | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -71,10 +75,10 @@ export function useOneBotInstanceConfig(
|
|||||||
const selectedUinRef = useRef(selectedUin);
|
const selectedUinRef = useRef(selectedUin);
|
||||||
selectedUinRef.current = 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(() => {
|
useEffect(() => {
|
||||||
if (!selectedUin && accounts.length > 0) onSelectedUinChange(accounts[0].uin);
|
if (options.selectedUin === null && selectedUin) onSelectedUinChange(selectedUin);
|
||||||
}, [accounts, selectedUin, onSelectedUinChange]);
|
}, [options.selectedUin, selectedUin, onSelectedUinChange]);
|
||||||
|
|
||||||
// Load on UIN change. The api client already runs normalizeOneBotConfig.
|
// Load on UIN change. The api client already runs normalizeOneBotConfig.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in new issue
Block a user