Refactor Mihomo proxy groups component to improve loading state management
- Introduced `untrack` from Svelte to prevent infinite rendering loops during loading state changes. - Enhanced loading state handling by ensuring that loading notifications are managed correctly without causing UI flickering. - Improved overall data fetching logic for better user experience during proxy updates.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import { ApiError, fetchMihomoJson, mihomoPut } from '$lib/api/client.js';
|
||||
import type { MihomoProxiesResponse, MihomoProxyEntry } from '$lib/api/mihomo-types.js';
|
||||
import { Button } from '$lib/components/ui/button/index.js';
|
||||
@@ -45,8 +46,10 @@
|
||||
async function loadProxies() {
|
||||
const a = alias;
|
||||
if (!a) return;
|
||||
const notify = onLoadingChange;
|
||||
proxiesLoading = true;
|
||||
onLoadingChange?.(true);
|
||||
// Иначе $effect подпишется на проп-колбэк: новая fn каждый рендер родителя → бесконечный цикл /proxies
|
||||
untrack(() => notify?.(true));
|
||||
proxiesErr = null;
|
||||
try {
|
||||
proxiesData = await fetchMihomoJson<MihomoProxiesResponse>(a, 'proxies');
|
||||
@@ -55,7 +58,7 @@
|
||||
// не затираем успешный снимок при сбое обновления — без мерцания UI
|
||||
} finally {
|
||||
proxiesLoading = false;
|
||||
onLoadingChange?.(false);
|
||||
untrack(() => notify?.(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user