A modern and elegant dashboard for network traffic visualization and analysis.
feat: Introduce `useStableTimeRange` hook, `keepPreviousByIdentity` query placeholder, and `ExpandReveal` UI component.
luolei4c713a95d5cb
diff --git a/apps/web/app/[locale]/page.tsx b/apps/web/app/[locale]/page.tsxindex faa195b..4afdfc9 100644--- a/apps/web/app/[locale]/page.tsx+++ b/apps/web/app/[locale]/page.tsx@@ -3,7 +3,7 @@import { useEffect, useState, useCallback, memo, useMemo } from "react";import { useTranslations, useLocale } from "next-intl";import { useTheme } from "next-themes";-import { keepPreviousData, useIsFetching, useQuery, useQueryClient } from "@tanstack/react-query";+import { keepPreviousData, useQuery, useQueryClient } from "@tanstack/react-query";import {Globe,MapPin,@@ -75,6 +75,7 @@ import {getDevicesQueryKey,getSummaryQueryKey,} from "@/lib/stats-query-keys";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";import { cn } from "@/lib/utils";import type { StatsSummary, CountryStats, DeviceStats } from "@clashmaster/shared";@@ -246,10 +247,7 @@ const DevicesContent = memo(function DevicesContent({timeRange: TimeRange;backendStatus: BackendStatus;}) {- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const stableTimeRange = useStableTimeRange(timeRange);const devicesQuery = useQuery({queryKey: getDevicesQueryKey(activeBackendId, 50, stableTimeRange),@@ -311,14 +309,13 @@ export default function DashboardPage() {const [isFirstTime, setIsFirstTime] = useState(false);const [showAboutDialog, setShowAboutDialog] = useState(false);- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const stableTimeRange = useStableTimeRange(timeRange);const backendsQuery = useQuery({queryKey: ["backends"],queryFn: () => api.getBackends(),+ refetchInterval: autoRefresh ? 5000 : false,+ refetchIntervalInBackground: true,});const backends = backendsQuery.data ?? [];@@ -332,13 +329,12 @@ export default function DashboardPage() {);const activeBackendId = activeBackend?.id;- const needsSummary = activeTab === "overview";const needsCountries = activeTab === "overview" || activeTab === "countries";const summaryQuery = useQuery({queryKey: getSummaryQueryKey(activeBackendId, stableTimeRange),queryFn: () => api.getSummary(activeBackendId, stableTimeRange),- enabled: !!activeBackendId && needsSummary,+ enabled: !!activeBackendId,placeholderData: keepPreviousData,});@@ -351,35 +347,36 @@ export default function DashboardPage() {const data: StatsSummary | null = summaryQuery.data ?? null;const countryData: CountryStats[] = countriesQuery.data ?? [];- const statsFetchingCount = useIsFetching({ queryKey: ["stats"] });- const isLoading = isManualRefreshing || statsFetchingCount > 0;-- const queryError = useMemo(() => {- if (needsSummary && summaryQuery.error) {- return summaryQuery.error instanceof Error- ? summaryQuery.error.message- : "Unknown error";- }- if (needsCountries && countriesQuery.error) {- return countriesQuery.error instanceof Error- ? countriesQuery.error.message- : "Unknown error";- }- return null;- }, [needsSummary, summaryQuery.error, needsCountries, countriesQuery.error]);+ const isLoading = isManualRefreshing;++ const summaryError = useMemo(() => {+ if (!summaryQuery.error) return null;+ return summaryQuery.error instanceof Error+ ? summaryQuery.error.message+ : "Unknown error";+ }, [summaryQuery.error]);++ const countriesError = useMemo(() => {+ if (!countriesQuery.error) return null;+ return countriesQuery.error instanceof Error+ ? countriesQuery.error.message+ : "Unknown error";+ }, [countriesQuery.error]);++ const queryError = summaryError ?? countriesError;const backendStatus: BackendStatus = useMemo(() => {if (!activeBackend) return "unknown";- if (queryError) return "unhealthy";+ if (summaryError) return "unhealthy";if (activeBackend.listening) return "healthy";return "unhealthy";- }, [activeBackend, queryError]);+ }, [activeBackend, summaryError]);const backendStatusHint = useMemo(() => {- if (queryError) return queryError;+ if (summaryError) return summaryError;if (activeBackend && !activeBackend.listening) return dashboardT("backendUnavailableHint");return null;- }, [queryError, activeBackend, dashboardT]);+ }, [summaryError, activeBackend, dashboardT]);const refreshNow = useCallback(async (showLoading = false) => {@@ -390,7 +387,10 @@ export default function DashboardPage() {if (isRollingTimePreset(timePreset)) {setTimeRange(getPresetTimeRange(timePreset));}- await queryClient.invalidateQueries({ queryKey: ["stats"] });+ await Promise.all([+ queryClient.invalidateQueries({ queryKey: ["stats"] }),+ queryClient.invalidateQueries({ queryKey: ["backends"] }),+ ]);} finally {if (showLoading) {setIsManualRefreshing(false);@@ -444,6 +444,7 @@ export default function DashboardPage() {if (!autoRefresh || !isRollingTimePreset(timePreset)) return;const interval = setInterval(() => {setTimeRange(getPresetTimeRange(timePreset));+ queryClient.removeQueries({ queryKey: ["stats"], type: "inactive" });}, 5000);return () => clearInterval(interval);}, [autoRefresh, timePreset]);@@ -455,7 +456,7 @@ export default function DashboardPage() {queryClient.invalidateQueries({ queryKey: ["stats"] });}, 5000);return () => clearInterval(interval);- }, [autoRefresh, timePreset, queryClient]);+ }, [autoRefresh, timePreset]);const renderContent = () => {switch (activeTab) {diff --git a/apps/web/components/country-traffic-list.tsx b/apps/web/components/country-traffic-list.tsxindex 100994a..54f23e8 100644--- a/apps/web/components/country-traffic-list.tsx+++ b/apps/web/components/country-traffic-list.tsx@@ -21,6 +21,10 @@ function getContinentColor(continent: string): string {return CONTINENT_COLORS[continent] || CONTINENT_COLORS.Unknown;}+function formatBytesNoWrap(value: number): string {+ return formatBytes(value).replace(" ", "\u00A0");+}+export function CountryTrafficList({ data }: CountryTrafficListProps) {const countries = useMemo(() => {if (!data) return [];@@ -70,8 +74,8 @@ export function CountryTrafficList({ data }: CountryTrafficListProps) {<div className="space-y-1.5">{/* Total */}<div className="flex items-baseline justify-between">- <span className="text-lg font-bold tabular-nums">- {formatBytes(country.total)}+ <span className="text-base sm:text-lg font-bold tabular-nums whitespace-nowrap">+ {formatBytesNoWrap(country.total)}</span><span className="text-xs text-muted-foreground">{percentage.toFixed(1)}%@@ -88,13 +92,13 @@ export function CountryTrafficList({ data }: CountryTrafficListProps) {{/* DL/UL row */}<div className="flex items-center justify-between text-xs">- <span className="flex items-center gap-0.5 text-blue-500">+ <span className="flex items-center gap-0.5 text-blue-500 whitespace-nowrap"><ArrowDown className="w-3 h-3" />- {formatBytes(country.totalDownload)}+ {formatBytesNoWrap(country.totalDownload)}</span>- <span className="flex items-center gap-0.5 text-purple-500">+ <span className="flex items-center gap-0.5 text-purple-500 whitespace-nowrap"><ArrowUp className="w-3 h-3" />- {formatBytes(country.totalUpload)}+ {formatBytesNoWrap(country.totalUpload)}</span></div>diff --git a/apps/web/components/domains-table.tsx b/apps/web/components/domains-table.tsxindex 8c22988..ee48109 100644--- a/apps/web/components/domains-table.tsx+++ b/apps/web/components/domains-table.tsx@@ -9,10 +9,12 @@ import { Button } from "@/components/ui/button";import { Favicon } from "@/components/favicon";import { DomainExpandedDetails } from "@/components/stats-tables/expanded-details";import { ProxyChainBadge } from "@/components/proxy-chain-badge";+import { ExpandReveal } from "@/components/ui/expand-reveal";import { formatBytes, formatNumber, formatDuration } from "@/lib/utils";import { cn } from "@/lib/utils";import type { DomainStats } from "@clashmaster/shared";import { api, type TimeRange } from "@/lib/api";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";import {getDomainIPDetailsQueryKey,getDomainProxyStatsQueryKey,@@ -38,10 +40,8 @@ type PageSize = typeof PAGE_SIZE_OPTIONS[number];export function DomainsTable({ activeBackendId, timeRange }: DomainsTableProps) {const t = useTranslations("domains");- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const stableTimeRange = useStableTimeRange(timeRange);+ const detailTimeRange = stableTimeRange;const [search, setSearch] = useState("");const [debouncedSearch, setDebouncedSearch] = useState("");const [sortKey, setSortKey] = useState<SortKey>("totalDownload");@@ -96,17 +96,33 @@ export function DomainsTable({ activeBackendId, timeRange }: DomainsTableProps)}, [activeBackendId]);const expandedDomainProxyQuery = useQuery({- queryKey: getDomainProxyStatsQueryKey(expandedDomain, activeBackendId, stableTimeRange),- queryFn: () => api.getDomainProxyStats(expandedDomain!, activeBackendId, stableTimeRange),+ queryKey: getDomainProxyStatsQueryKey(expandedDomain, activeBackendId, detailTimeRange),+ queryFn: () => api.getDomainProxyStats(expandedDomain!, activeBackendId, detailTimeRange),enabled: !!activeBackendId && !!expandedDomain,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) => {+ const prevKey = (previousQuery?.queryKey?.[2] ?? null) as+ | { domain?: string; backendId?: number | null }+ | null;+ if (!prevKey) return undefined;+ if (prevKey.domain !== (expandedDomain ?? "")) return undefined;+ if (prevKey.backendId !== (activeBackendId ?? null)) return undefined;+ return previousData;+ },});const expandedDomainIPDetailsQuery = useQuery({- queryKey: getDomainIPDetailsQueryKey(expandedDomain, activeBackendId, stableTimeRange),- queryFn: () => api.getDomainIPDetails(expandedDomain!, activeBackendId, stableTimeRange),+ queryKey: getDomainIPDetailsQueryKey(expandedDomain, activeBackendId, detailTimeRange),+ queryFn: () => api.getDomainIPDetails(expandedDomain!, activeBackendId, detailTimeRange),enabled: !!activeBackendId && !!expandedDomain,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) => {+ const prevKey = (previousQuery?.queryKey?.[2] ?? null) as+ | { domain?: string; backendId?: number | null }+ | null;+ if (!prevKey) return undefined;+ if (prevKey.domain !== (expandedDomain ?? "")) return undefined;+ if (prevKey.backendId !== (activeBackendId ?? null)) return undefined;+ return previousData;+ },});const handleSort = (key: SortKey) => {@@ -407,6 +423,7 @@ export function DomainsTable({ activeBackendId, timeRange }: DomainsTableProps){/* Expanded Details: Proxy Traffic + IP List */}{isExpanded && (+ <ExpandReveal><DomainExpandedDetailsdomain={domain}proxyStats={expandedDomainProxyQuery.data ?? []}@@ -425,6 +442,7 @@ export function DomainsTable({ activeBackendId, timeRange }: DomainsTableProps)conn: t("conn"),}}/>+ </ExpandReveal>)}</div>);diff --git a/apps/web/components/interactive-device-stats.tsx b/apps/web/components/interactive-device-stats.tsxindex e9527fb..e9c7296 100644--- a/apps/web/components/interactive-device-stats.tsx+++ b/apps/web/components/interactive-device-stats.tsx@@ -3,7 +3,7 @@import { useState, useCallback, useMemo, useEffect } from "react";import { Loader2, BarChart3, Link2, Smartphone } from "lucide-react";import { useTranslations } from "next-intl";-import { keepPreviousData, useQuery } from "@tanstack/react-query";+import { useQuery } from "@tanstack/react-query";import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip, BarChart, Bar, XAxis, YAxis, Cell as BarCell, LabelList } from "recharts";import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";@@ -15,6 +15,8 @@ import {getDeviceDomainsQueryKey,getDeviceIPsQueryKey,} from "@/lib/stats-query-keys";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";+import { keepPreviousByIdentity } from "@/lib/query-placeholder";import { Favicon } from "@/components/favicon";import { DomainStatsTable, IPStatsTable } from "@/components/stats-tables";import { COLORS } from "@/lib/stats-utils";@@ -47,10 +49,7 @@ export function InteractiveDeviceStats({const t = useTranslations("devices");const domainsT = useTranslations("domains");const backendT = useTranslations("dashboard");- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const detailTimeRange = useStableTimeRange(timeRange);const [selectedDevice, setSelectedDevice] = useState<string | null>(null);const [activeTab, setActiveTab] = useState("domains");@@ -94,27 +93,35 @@ export function InteractiveDeviceStats({}, [chartData, selectedDevice]);const deviceDomainsQuery = useQuery({- queryKey: getDeviceDomainsQueryKey(selectedDevice, activeBackendId, stableTimeRange),+ queryKey: getDeviceDomainsQueryKey(selectedDevice, activeBackendId, detailTimeRange),queryFn: () =>api.getDeviceDomains(selectedDevice!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedDevice,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ sourceIP: selectedDevice ?? "",+ backendId: activeBackendId ?? null,+ }),});const deviceIPsQuery = useQuery({- queryKey: getDeviceIPsQueryKey(selectedDevice, activeBackendId, stableTimeRange),+ queryKey: getDeviceIPsQueryKey(selectedDevice, activeBackendId, detailTimeRange),queryFn: () =>api.getDeviceIPs(selectedDevice!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedDevice,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ sourceIP: selectedDevice ?? "",+ backendId: activeBackendId ?? null,+ }),});const deviceDomains = deviceDomainsQuery.data ?? [];diff --git a/apps/web/components/interactive-proxy-stats.tsx b/apps/web/components/interactive-proxy-stats.tsxindex 17a0657..9030921 100644--- a/apps/web/components/interactive-proxy-stats.tsx+++ b/apps/web/components/interactive-proxy-stats.tsx@@ -12,6 +12,8 @@ import { CountryFlag, extractCountryCodeFromText, stripLeadingFlagEmoji } from "import { formatBytes, formatNumber } from "@/lib/utils";import { cn } from "@/lib/utils";import { api, type TimeRange } from "@/lib/api";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";+import { keepPreviousByIdentity } from "@/lib/query-placeholder";import {getProxiesQueryKey,getProxyDomainsQueryKey,@@ -72,10 +74,8 @@ export function InteractiveProxyStats({const t = useTranslations("proxies");const domainsT = useTranslations("domains");const backendT = useTranslations("dashboard");- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const stableTimeRange = useStableTimeRange(timeRange);+ const detailTimeRange = stableTimeRange;const proxyListQuery = useQuery({queryKey: getProxiesQueryKey(activeBackendId, 50, stableTimeRange),@@ -129,27 +129,35 @@ export function InteractiveProxyStats({}, [chartData, selectedProxy]);const proxyDomainsQuery = useQuery({- queryKey: getProxyDomainsQueryKey(selectedProxy, activeBackendId, stableTimeRange),+ queryKey: getProxyDomainsQueryKey(selectedProxy, activeBackendId, detailTimeRange),queryFn: () =>api.getProxyDomains(selectedProxy!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedProxy,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ chain: selectedProxy ?? "",+ backendId: activeBackendId ?? null,+ }),});const proxyIPsQuery = useQuery({- queryKey: getProxyIPsQueryKey(selectedProxy, activeBackendId, stableTimeRange),+ queryKey: getProxyIPsQueryKey(selectedProxy, activeBackendId, detailTimeRange),queryFn: () =>api.getProxyIPs(selectedProxy!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedProxy,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ chain: selectedProxy ?? "",+ backendId: activeBackendId ?? null,+ }),});const proxyDomains = proxyDomainsQuery.data ?? [];diff --git a/apps/web/components/interactive-rule-stats.tsx b/apps/web/components/interactive-rule-stats.tsxindex 24a0d06..eca83aa 100644--- a/apps/web/components/interactive-rule-stats.tsx+++ b/apps/web/components/interactive-rule-stats.tsx@@ -20,6 +20,8 @@ import {import { formatBytes, formatNumber } from "@/lib/utils";import { cn } from "@/lib/utils";import { api, type ClashRulesResponse, type TimeRange } from "@/lib/api";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";+import { keepPreviousByIdentity } from "@/lib/query-placeholder";import {getRuleDomainsQueryKey,getRuleIPsQueryKey,@@ -33,6 +35,7 @@ import { CountryFlag } from "@/components/country-flag";import { Favicon } from "@/components/favicon";import { ProxyChainBadge } from "@/components/proxy-chain-badge";import { DomainExpandedDetails, IPExpandedDetails } from "@/components/stats-tables/expanded-details";+import { ExpandReveal } from "@/components/ui/expand-reveal";import { UnifiedRuleChainFlow } from "@/components/rule-chain-flow";import type { RuleStats, DomainStats, IPStats } from "@clashmaster/shared";@@ -111,10 +114,8 @@ export function InteractiveRuleStats({const domainsT = useTranslations("domains");const ipsT = useTranslations("ips");const backendT = useTranslations("dashboard");- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const stableTimeRange = useStableTimeRange(timeRange);+ const detailTimeRange = stableTimeRange;const ruleListQuery = useQuery({queryKey: getRulesQueryKey(activeBackendId, 50, stableTimeRange),@@ -265,7 +266,7 @@ export function InteractiveRuleStats({};const expandedDomainProxyQuery = useQuery({- queryKey: getDomainProxyStatsQueryKey(expandedDomain, activeBackendId, stableTimeRange, {+ queryKey: getDomainProxyStatsQueryKey(expandedDomain, activeBackendId, detailTimeRange, {rule: selectedRule ?? undefined,}),queryFn: () =>@@ -273,14 +274,19 @@ export function InteractiveRuleStats({selectedRule!,expandedDomain!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedRule && !!expandedDomain,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ domain: expandedDomain ?? "",+ backendId: activeBackendId ?? null,+ rule: selectedRule ?? "",+ }),});const expandedDomainIPDetailsQuery = useQuery({- queryKey: getDomainIPDetailsQueryKey(expandedDomain, activeBackendId, stableTimeRange, {+ queryKey: getDomainIPDetailsQueryKey(expandedDomain, activeBackendId, detailTimeRange, {rule: selectedRule ?? undefined,}),queryFn: () =>@@ -288,14 +294,19 @@ export function InteractiveRuleStats({selectedRule!,expandedDomain!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedRule && !!expandedDomain,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ domain: expandedDomain ?? "",+ backendId: activeBackendId ?? null,+ rule: selectedRule ?? "",+ }),});const expandedIPProxyQuery = useQuery({- queryKey: getIPProxyStatsQueryKey(expandedIP, activeBackendId, stableTimeRange, {+ queryKey: getIPProxyStatsQueryKey(expandedIP, activeBackendId, detailTimeRange, {rule: selectedRule ?? undefined,}),queryFn: () =>@@ -303,14 +314,19 @@ export function InteractiveRuleStats({selectedRule!,expandedIP!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedRule && !!expandedIP,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ ip: expandedIP ?? "",+ backendId: activeBackendId ?? null,+ rule: selectedRule ?? "",+ }),});const expandedIPDomainDetailsQuery = useQuery({- queryKey: getIPDomainDetailsQueryKey(expandedIP, activeBackendId, stableTimeRange, {+ queryKey: getIPDomainDetailsQueryKey(expandedIP, activeBackendId, detailTimeRange, {rule: selectedRule ?? undefined,}),queryFn: () =>@@ -318,34 +334,47 @@ export function InteractiveRuleStats({selectedRule!,expandedIP!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedRule && !!expandedIP,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ ip: expandedIP ?? "",+ backendId: activeBackendId ?? null,+ rule: selectedRule ?? "",+ }),});const ruleDomainsQuery = useQuery({- queryKey: getRuleDomainsQueryKey(selectedRule, activeBackendId, stableTimeRange),+ queryKey: getRuleDomainsQueryKey(selectedRule, activeBackendId, detailTimeRange),queryFn: () =>api.getRuleDomains(selectedRule!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedRule,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ rule: selectedRule ?? "",+ backendId: activeBackendId ?? null,+ }),});const ruleIPsQuery = useQuery({- queryKey: getRuleIPsQueryKey(selectedRule, activeBackendId, stableTimeRange),+ queryKey: getRuleIPsQueryKey(selectedRule, activeBackendId, detailTimeRange),queryFn: () =>api.getRuleIPs(selectedRule!,activeBackendId,- stableTimeRange,+ detailTimeRange,),enabled: !!activeBackendId && !!selectedRule,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ rule: selectedRule ?? "",+ backendId: activeBackendId ?? null,+ }),});const ruleDomains: DomainStats[] = ruleDomainsQuery.data ?? [];@@ -1099,24 +1128,26 @@ export function InteractiveRuleStats({{/* Expanded Details: Proxy Traffic + Associated IPs */}{isExpanded && (- <DomainExpandedDetails- domain={domain}- proxyStats={expandedDomainProxyQuery.data ?? []}- proxyStatsLoading={- expandedDomainProxyQuery.isLoading &&- !expandedDomainProxyQuery.data- }- ipDetails={expandedDomainIPDetailsQuery.data ?? []}- ipDetailsLoading={- expandedDomainIPDetailsQuery.isLoading &&- !expandedDomainIPDetailsQuery.data- }- labels={{- proxyTraffic: domainsT("proxyTraffic"),- associatedIPs: domainsT("associatedIPs"),- conn: domainsT("conn"),- }}- />+ <ExpandReveal>+ <DomainExpandedDetails+ domain={domain}+ proxyStats={expandedDomainProxyQuery.data ?? []}+ proxyStatsLoading={+ expandedDomainProxyQuery.isLoading &&+ !expandedDomainProxyQuery.data+ }+ ipDetails={expandedDomainIPDetailsQuery.data ?? []}+ ipDetailsLoading={+ expandedDomainIPDetailsQuery.isLoading &&+ !expandedDomainIPDetailsQuery.data+ }+ labels={{+ proxyTraffic: domainsT("proxyTraffic"),+ associatedIPs: domainsT("associatedIPs"),+ conn: domainsT("conn"),+ }}+ />+ </ExpandReveal>)}</div>);@@ -1470,25 +1501,27 @@ export function InteractiveRuleStats({{/* Expanded Details: Proxy Traffic + Associated Domains */}{isExpanded && (- <IPExpandedDetails- ip={ip}- proxyStats={expandedIPProxyQuery.data ?? []}- proxyStatsLoading={- expandedIPProxyQuery.isLoading &&- !expandedIPProxyQuery.data- }- domainDetails={expandedIPDomainDetailsQuery.data ?? []}- domainDetailsLoading={- expandedIPDomainDetailsQuery.isLoading &&- !expandedIPDomainDetailsQuery.data- }- associatedDomainsIcon="link"- labels={{- proxyTraffic: ipsT("proxyTraffic"),- associatedDomains: ipsT("associatedDomains"),- conn: ipsT("conn"),- }}- />+ <ExpandReveal>+ <IPExpandedDetails+ ip={ip}+ proxyStats={expandedIPProxyQuery.data ?? []}+ proxyStatsLoading={+ expandedIPProxyQuery.isLoading &&+ !expandedIPProxyQuery.data+ }+ domainDetails={expandedIPDomainDetailsQuery.data ?? []}+ domainDetailsLoading={+ expandedIPDomainDetailsQuery.isLoading &&+ !expandedIPDomainDetailsQuery.data+ }+ associatedDomainsIcon="link"+ labels={{+ proxyTraffic: ipsT("proxyTraffic"),+ associatedDomains: ipsT("associatedDomains"),+ conn: ipsT("conn"),+ }}+ />+ </ExpandReveal>)}</div>);diff --git a/apps/web/components/ips-table.tsx b/apps/web/components/ips-table.tsxindex d79bfd8..f009d91 100644--- a/apps/web/components/ips-table.tsx+++ b/apps/web/components/ips-table.tsx@@ -25,8 +25,10 @@ import { formatBytes, formatNumber } from "@/lib/utils";import { cn } from "@/lib/utils";import { IPExpandedDetails } from "@/components/stats-tables/expanded-details";import { ProxyChainBadge } from "@/components/proxy-chain-badge";+import { ExpandReveal } from "@/components/ui/expand-reveal";import type { IPStats } from "@clashmaster/shared";import { api, type TimeRange } from "@/lib/api";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";import {getIPDomainDetailsQueryKey,getIPProxyStatsQueryKey,@@ -78,10 +80,8 @@ const getIPColor = (ip: string) => {export function IPsTable({ activeBackendId, timeRange }: IPsTableProps) {const t = useTranslations("ips");- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const stableTimeRange = useStableTimeRange(timeRange);+ const detailTimeRange = stableTimeRange;const [search, setSearch] = useState("");const [debouncedSearch, setDebouncedSearch] = useState("");const [sortKey, setSortKey] = useState<SortKey>("totalDownload");@@ -138,17 +138,33 @@ export function IPsTable({ activeBackendId, timeRange }: IPsTableProps) {}, [activeBackendId]);const expandedIPProxyQuery = useQuery({- queryKey: getIPProxyStatsQueryKey(expandedIP, activeBackendId, stableTimeRange),- queryFn: () => api.getIPProxyStats(expandedIP!, activeBackendId, stableTimeRange),+ queryKey: getIPProxyStatsQueryKey(expandedIP, activeBackendId, detailTimeRange),+ queryFn: () => api.getIPProxyStats(expandedIP!, activeBackendId, detailTimeRange),enabled: !!activeBackendId && !!expandedIP,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) => {+ const prevKey = (previousQuery?.queryKey?.[2] ?? null) as+ | { ip?: string; backendId?: number | null }+ | null;+ if (!prevKey) return undefined;+ if (prevKey.ip !== (expandedIP ?? "")) return undefined;+ if (prevKey.backendId !== (activeBackendId ?? null)) return undefined;+ return previousData;+ },});const expandedIPDomainDetailsQuery = useQuery({- queryKey: getIPDomainDetailsQueryKey(expandedIP, activeBackendId, stableTimeRange),- queryFn: () => api.getIPDomainDetails(expandedIP!, activeBackendId, stableTimeRange),+ queryKey: getIPDomainDetailsQueryKey(expandedIP, activeBackendId, detailTimeRange),+ queryFn: () => api.getIPDomainDetails(expandedIP!, activeBackendId, detailTimeRange),enabled: !!activeBackendId && !!expandedIP,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) => {+ const prevKey = (previousQuery?.queryKey?.[2] ?? null) as+ | { ip?: string; backendId?: number | null }+ | null;+ if (!prevKey) return undefined;+ if (prevKey.ip !== (expandedIP ?? "")) return undefined;+ if (prevKey.backendId !== (activeBackendId ?? null)) return undefined;+ return previousData;+ },});const handleSort = (key: SortKey) => {@@ -474,6 +490,7 @@ export function IPsTable({ activeBackendId, timeRange }: IPsTableProps) {{/* Expanded Details: Proxy Traffic + Domains List */}{isExpanded && (+ <ExpandReveal><IPExpandedDetailsip={ip}proxyStats={expandedIPProxyQuery.data ?? []}@@ -493,6 +510,7 @@ export function IPsTable({ activeBackendId, timeRange }: IPsTableProps) {conn: t("conn"),}}/>+ </ExpandReveal>)}</div>);diff --git a/apps/web/components/rule-chain-flow.tsx b/apps/web/components/rule-chain-flow.tsxindex 782dd6b..0145775 100644--- a/apps/web/components/rule-chain-flow.tsx+++ b/apps/web/components/rule-chain-flow.tsx@@ -46,6 +46,7 @@ interface MergedChainNode {totalDownload: number;totalConnections: number;rules: string[];+ _zeroTraffic?: boolean;}interface AllChainFlowData {@@ -162,10 +163,10 @@ function MergedAnimatedFlowEdge({function MergedChainNodeComponent({data,}: {- data: MergedChainNode & { dimmed?: boolean; _zeroTraffic?: boolean };+ data: MergedChainNode & { dimmed?: boolean };}) {const dimmed = data.dimmed;- const zeroTraffic = (data as any)._zeroTraffic;+ const zeroTraffic = data._zeroTraffic;const wrapStyle: React.CSSProperties = {opacity: dimmed ? 0.12 : zeroTraffic ? 0.5 : 1,filter: zeroTraffic ? "grayscale(100%)" : undefined,@@ -377,6 +378,7 @@ function FlowRenderer({}) {const { fitView } = useReactFlow();const { resolvedTheme } = useTheme();+ const t = useTranslations("rules");const isDark = resolvedTheme === "dark";const [nodes, setNodes, onNodesChange] = useNodesState<Node>([]);const [edges, setEdges, onEdgesChange] = useEdgesState<Edge>([]);@@ -520,7 +522,7 @@ function FlowRenderer({data: {...node,dimmed: activeNodeSet ? !activeNodeSet.has(idx) : false,- _zeroTraffic: !!(node as any)._zeroTraffic,+ _zeroTraffic: !!node._zeroTraffic,},sourcePosition: Position.Right,targetPosition: Position.Left,@@ -536,7 +538,7 @@ function FlowRenderer({const isToProxy = targetNode?.nodeType === "proxy";const isDimmed = activeLinkSet ? !activeLinkSet.has(idx) : false;const isZeroTraffic = !!(- (sourceNode as any)?._zeroTraffic || (targetNode as any)?._zeroTraffic+ sourceNode?._zeroTraffic || targetNode?._zeroTraffic);return {id: `e-${link.source}-${link.target}`,@@ -653,7 +655,7 @@ function FlowRenderer({<Controls showInteractive={false} showFitView={false}><ControlButtononClick={onToggleFullscreen}- title={isFullscreen ? "Exit fullscreen" : "Fullscreen"}>+ title={isFullscreen ? t("exitFullscreen") : t("fullscreen")}>{isFullscreen ? (<Minimize2 className="h-4 w-4" />) : (@@ -871,7 +873,7 @@ export function UnifiedRuleChainFlow({totalConnections: 0,rules: [],_zeroTraffic: true,- } as MergedChainNode & { _zeroTraffic?: boolean } as any);+ });}}}diff --git a/apps/web/components/stats-tables/domain-stats-table.tsx b/apps/web/components/stats-tables/domain-stats-table.tsxindex 0437ee1..d03fff7 100644--- a/apps/web/components/stats-tables/domain-stats-table.tsx+++ b/apps/web/components/stats-tables/domain-stats-table.tsx@@ -1,7 +1,7 @@"use client";import { useState, useMemo, useEffect } from "react";-import { keepPreviousData, useQuery } from "@tanstack/react-query";+import { useQuery } from "@tanstack/react-query";import {ChevronLeft,ChevronRight,@@ -27,6 +27,8 @@ import {import { formatBytes, formatNumber } from "@/lib/utils";import { cn } from "@/lib/utils";import { api, type TimeRange } from "@/lib/api";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";+import { keepPreviousByIdentity } from "@/lib/query-placeholder";import {getDomainIPDetailsQueryKey,getDomainProxyStatsQueryKey,@@ -34,6 +36,7 @@ import {import { Favicon } from "@/components/favicon";import { DomainExpandedDetails } from "@/components/stats-tables/expanded-details";import { ProxyChainBadge } from "@/components/proxy-chain-badge";+import { ExpandReveal } from "@/components/ui/expand-reveal";import {PAGE_SIZE_OPTIONS,getPageNumbers,@@ -71,10 +74,7 @@ export function DomainStatsTable({showProxyTrafficInExpand = true,}: DomainStatsTableProps) {const t = useTranslations("domains");- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const detailTimeRange = useStableTimeRange(timeRange);const [page, setPage] = useState(1);const [pageSize, setPageSize] = useState<PageSize>(10);@@ -89,7 +89,7 @@ export function DomainStatsTable({}, [activeBackendId, sourceIP, sourceChain, richExpand]);const expandedDomainProxyQuery = useQuery({- queryKey: getDomainProxyStatsQueryKey(expandedDomain, activeBackendId, stableTimeRange, {+ queryKey: getDomainProxyStatsQueryKey(expandedDomain, activeBackendId, detailTimeRange, {sourceIP,sourceChain,}),@@ -97,16 +97,22 @@ export function DomainStatsTable({api.getDomainProxyStats(expandedDomain!,activeBackendId,- stableTimeRange,+ detailTimeRange,sourceIP,sourceChain,),enabled: richExpand && !!activeBackendId && !!expandedDomain,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ domain: expandedDomain ?? "",+ backendId: activeBackendId ?? null,+ sourceIP: sourceIP ?? "",+ sourceChain: sourceChain ?? "",+ }),});const expandedDomainIPDetailsQuery = useQuery({- queryKey: getDomainIPDetailsQueryKey(expandedDomain, activeBackendId, stableTimeRange, {+ queryKey: getDomainIPDetailsQueryKey(expandedDomain, activeBackendId, detailTimeRange, {sourceIP,sourceChain,}),@@ -114,12 +120,18 @@ export function DomainStatsTable({api.getDomainIPDetails(expandedDomain!,activeBackendId,- stableTimeRange,+ detailTimeRange,sourceIP,sourceChain,),enabled: richExpand && !!activeBackendId && !!expandedDomain,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ domain: expandedDomain ?? "",+ backendId: activeBackendId ?? null,+ sourceIP: sourceIP ?? "",+ sourceChain: sourceChain ?? "",+ }),});const handleSort = (key: DomainSortKey) => {@@ -383,26 +395,28 @@ export function DomainStatsTable({</div>{isExpanded && (- <DomainExpandedDetails- domain={domain}- richExpand={richExpand}- proxyStats={expandedDomainProxyQuery.data ?? []}- proxyStatsLoading={- expandedDomainProxyQuery.isLoading &&- !expandedDomainProxyQuery.data- }- ipDetails={expandedDomainIPDetailsQuery.data ?? []}- ipDetailsLoading={- expandedDomainIPDetailsQuery.isLoading &&- !expandedDomainIPDetailsQuery.data- }- labels={{- proxyTraffic: t("proxyTraffic"),- associatedIPs: t("associatedIPs"),- conn: t("conn"),- }}- showProxyTraffic={showProxyTrafficInExpand}- />+ <ExpandReveal>+ <DomainExpandedDetails+ domain={domain}+ richExpand={richExpand}+ proxyStats={expandedDomainProxyQuery.data ?? []}+ proxyStatsLoading={+ expandedDomainProxyQuery.isLoading &&+ !expandedDomainProxyQuery.data+ }+ ipDetails={expandedDomainIPDetailsQuery.data ?? []}+ ipDetailsLoading={+ expandedDomainIPDetailsQuery.isLoading &&+ !expandedDomainIPDetailsQuery.data+ }+ labels={{+ proxyTraffic: t("proxyTraffic"),+ associatedIPs: t("associatedIPs"),+ conn: t("conn"),+ }}+ showProxyTraffic={showProxyTrafficInExpand}+ />+ </ExpandReveal>)}</div>);diff --git a/apps/web/components/stats-tables/expanded-details.tsx b/apps/web/components/stats-tables/expanded-details.tsxindex a87144f..5a0f4eb 100644--- a/apps/web/components/stats-tables/expanded-details.tsx+++ b/apps/web/components/stats-tables/expanded-details.tsx@@ -60,6 +60,41 @@ function LoadingBlock() {);}+const MAX_ASSOCIATED_PLACEHOLDERS = 12;++function AssociatedLoadingList({ count }: { count: number }) {+ const safeCount = Number.isFinite(count) ? Math.max(0, Math.floor(count)) : 0;+ const renderCount = safeCount > 0 ? Math.min(safeCount, MAX_ASSOCIATED_PLACEHOLDERS) : 3;+ const remaining = safeCount > renderCount ? safeCount - renderCount : 0;++ return (+ <div className="space-y-2">+ {Array.from({ length: renderCount }).map((_, index) => (+ <div+ key={`placeholder-${index}`}+ className="px-3 py-2 rounded-lg bg-card border border-border/50 animate-pulse"+ >+ <div className="flex items-center justify-between mb-2">+ <div className="h-3.5 w-28 rounded bg-secondary/80" />+ <div className="h-3 w-10 rounded bg-secondary/70" />+ </div>+ <div className="h-1.5 w-full rounded-full bg-secondary/70 mb-2" />+ <div className="flex items-center gap-2">+ <div className="h-3 w-16 rounded bg-secondary/70" />+ <div className="h-3 w-14 rounded bg-secondary/70" />+ <div className="h-3 w-12 rounded bg-secondary/70" />+ </div>+ </div>+ ))}+ {remaining > 0 && (+ <div className="px-1 pt-1 text-[11px] text-muted-foreground tabular-nums">+ +{remaining}+ </div>+ )}+ </div>+ );+}+function TrafficBar({percent,downloadPercent,@@ -289,7 +324,7 @@ export function DomainExpandedDetails({{labels.associatedIPs}</p>{ipDetailsLoading ? (- <LoadingBlock />+ <AssociatedLoadingList count={domain.ips?.length ?? 0} />) : ipDetails.length > 0 ? (<div className="space-y-2">{ipDetails.map((ipStat) => {@@ -415,7 +450,7 @@ export function IPExpandedDetails({{labels.associatedDomains}</p>{domainDetailsLoading ? (- <LoadingBlock />+ <AssociatedLoadingList count={ip.domains?.length ?? 0} />) : domainDetails.length > 0 ? (<div className="space-y-2">{domainDetails.map((domain) => {diff --git a/apps/web/components/stats-tables/ip-stats-table.tsx b/apps/web/components/stats-tables/ip-stats-table.tsxindex 299a1db..d31408d 100644--- a/apps/web/components/stats-tables/ip-stats-table.tsx+++ b/apps/web/components/stats-tables/ip-stats-table.tsx@@ -1,7 +1,7 @@"use client";import { useState, useMemo, useEffect } from "react";-import { keepPreviousData, useQuery } from "@tanstack/react-query";+import { useQuery } from "@tanstack/react-query";import {ChevronLeft,ChevronRight,@@ -29,12 +29,15 @@ import {import { formatBytes, formatNumber } from "@/lib/utils";import { cn } from "@/lib/utils";import { api, type TimeRange } from "@/lib/api";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";+import { keepPreviousByIdentity } from "@/lib/query-placeholder";import {getIPDomainDetailsQueryKey,getIPProxyStatsQueryKey,} from "@/lib/stats-query-keys";import { IPExpandedDetails } from "@/components/stats-tables/expanded-details";import { ProxyChainBadge } from "@/components/proxy-chain-badge";+import { ExpandReveal } from "@/components/ui/expand-reveal";import {PAGE_SIZE_OPTIONS,getIPGradient,@@ -73,10 +76,7 @@ export function IPStatsTable({showProxyTrafficInExpand = true,}: IPStatsTableProps) {const t = useTranslations("ips");- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const detailTimeRange = useStableTimeRange(timeRange);const [page, setPage] = useState(1);const [pageSize, setPageSize] = useState<PageSize>(10);@@ -91,7 +91,7 @@ export function IPStatsTable({}, [activeBackendId, sourceIP, sourceChain, richExpand]);const expandedIPProxyQuery = useQuery({- queryKey: getIPProxyStatsQueryKey(expandedIP, activeBackendId, stableTimeRange, {+ queryKey: getIPProxyStatsQueryKey(expandedIP, activeBackendId, detailTimeRange, {sourceIP,sourceChain,}),@@ -99,16 +99,22 @@ export function IPStatsTable({api.getIPProxyStats(expandedIP!,activeBackendId,- stableTimeRange,+ detailTimeRange,sourceIP,sourceChain,),enabled: richExpand && !!activeBackendId && !!expandedIP,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ ip: expandedIP ?? "",+ backendId: activeBackendId ?? null,+ sourceIP: sourceIP ?? "",+ sourceChain: sourceChain ?? "",+ }),});const expandedIPDomainDetailsQuery = useQuery({- queryKey: getIPDomainDetailsQueryKey(expandedIP, activeBackendId, stableTimeRange, {+ queryKey: getIPDomainDetailsQueryKey(expandedIP, activeBackendId, detailTimeRange, {sourceIP,sourceChain,}),@@ -116,13 +122,19 @@ export function IPStatsTable({api.getIPDomainDetails(expandedIP!,activeBackendId,- stableTimeRange,+ detailTimeRange,sourceIP,undefined,sourceChain,),enabled: richExpand && !!activeBackendId && !!expandedIP,- placeholderData: keepPreviousData,+ placeholderData: (previousData, previousQuery) =>+ keepPreviousByIdentity(previousData, previousQuery, {+ ip: expandedIP ?? "",+ backendId: activeBackendId ?? null,+ sourceIP: sourceIP ?? "",+ sourceChain: sourceChain ?? "",+ }),});const handleSort = (key: IPSortKey) => {@@ -407,27 +419,29 @@ export function IPStatsTable({</div>{isExpanded && (- <IPExpandedDetails- ip={ip}- richExpand={richExpand}- proxyStats={expandedIPProxyQuery.data ?? []}- proxyStatsLoading={- expandedIPProxyQuery.isLoading &&- !expandedIPProxyQuery.data- }- domainDetails={expandedIPDomainDetailsQuery.data ?? []}- domainDetailsLoading={- expandedIPDomainDetailsQuery.isLoading &&- !expandedIPDomainDetailsQuery.data- }- associatedDomainsIcon="link"- labels={{- proxyTraffic: t("proxyTraffic"),- associatedDomains: t("associatedDomains"),- conn: t("conn"),- }}- showProxyTraffic={showProxyTrafficInExpand}- />+ <ExpandReveal>+ <IPExpandedDetails+ ip={ip}+ richExpand={richExpand}+ proxyStats={expandedIPProxyQuery.data ?? []}+ proxyStatsLoading={+ expandedIPProxyQuery.isLoading &&+ !expandedIPProxyQuery.data+ }+ domainDetails={expandedIPDomainDetailsQuery.data ?? []}+ domainDetailsLoading={+ expandedIPDomainDetailsQuery.isLoading &&+ !expandedIPDomainDetailsQuery.data+ }+ associatedDomainsIcon="link"+ labels={{+ proxyTraffic: t("proxyTraffic"),+ associatedDomains: t("associatedDomains"),+ conn: t("conn"),+ }}+ showProxyTraffic={showProxyTrafficInExpand}+ />+ </ExpandReveal>)}</div>);diff --git a/apps/web/components/top-domains-chart.tsx b/apps/web/components/top-domains-chart.tsxindex 3e39841..d4caf74 100644--- a/apps/web/components/top-domains-chart.tsx+++ b/apps/web/components/top-domains-chart.tsx@@ -20,6 +20,7 @@ import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";import { Favicon } from "@/components/favicon";import { formatBytes } from "@/lib/utils";import { api, type TimeRange } from "@/lib/api";+import { useStableTimeRange } from "@/lib/hooks/use-stable-time-range";import { getDomainsQueryKey } from "@/lib/stats-query-keys";import type { DomainStats } from "@clashmaster/shared";@@ -79,10 +80,7 @@ export function TopDomainsChart({ activeBackendId, timeRange }: TopDomainsChartP// Track container width to hide labels on small screensconst containerRef = useRef<HTMLDivElement>(null);const [containerWidth, setContainerWidth] = useState(0);- const stableTimeRange = useMemo<TimeRange | undefined>(() => {- if (!timeRange?.start && !timeRange?.end) return undefined;- return { start: timeRange.start, end: timeRange.end };- }, [timeRange?.start, timeRange?.end]);+ const stableTimeRange = useStableTimeRange(timeRange);const domainsQuery = useQuery({queryKey: getDomainsQueryKey(diff --git a/apps/web/components/ui/expand-reveal.tsx b/apps/web/components/ui/expand-reveal.tsxnew file mode 100644index 0000000..79780c0--- /dev/null+++ b/apps/web/components/ui/expand-reveal.tsx@@ -0,0 +1,22 @@+"use client";++import type { ReactNode } from "react";+import { cn } from "@/lib/utils";++interface ExpandRevealProps {+ children: ReactNode;+ className?: string;+}++export function ExpandReveal({ children, className }: ExpandRevealProps) {+ return (+ <div+ className={cn(+ "overflow-hidden motion-reduce:animate-none animate-in fade-in-0 slide-in-from-top-1 duration-200 ease-out",+ className,+ )}+ >+ {children}+ </div>+ );+}diff --git a/apps/web/lib/api.ts b/apps/web/lib/api.tsindex e5862fc..c85521a 100644--- a/apps/web/lib/api.ts+++ b/apps/web/lib/api.ts@@ -41,26 +41,10 @@ function resolveApiBase(): string {const API_BASE = resolveApiBase();const DETAIL_FETCH_LIMIT = 5000;-const GET_DEDUP_TTL_MS = 250;const inflightGetRequests = new Map<string, Promise<unknown>>();-const recentGetResponses = new Map<string, { expiresAt: number; data: unknown }>();--function pruneRecentGetResponses(now: number) {- if (recentGetResponses.size <= 200) return;- for (const [key, entry] of recentGetResponses) {- if (entry.expiresAt <= now) {- recentGetResponses.delete(key);- }- }-}async function fetchJson<T>(url: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET', body?: any): Promise<T> {if (method === "GET") {- const now = Date.now();- const recent = recentGetResponses.get(url);- if (recent && recent.expiresAt > now) {- return recent.data as T;- }const inflight = inflightGetRequests.get(url);if (inflight) {return inflight as Promise<T>;@@ -71,7 +55,7 @@ async function fetchJson<T>(url: string, method: 'GET' | 'POST' | 'PUT' | 'DELETmethod,headers: {},};-+// Only set Content-Type when there's a bodyif (body && method !== 'GET') {options.headers = {@@ -79,21 +63,14 @@ async function fetchJson<T>(url: string, method: 'GET' | 'POST' | 'PUT' | 'DELET};options.body = JSON.stringify(body);}-+const requestPromise = (async () => {- console.log(`[API] ${method} ${url}`);const res = await fetch(url, options);if (!res.ok) {console.error(`[API] Error ${res.status}: ${url}`);throw new Error(`API error: ${res.status}`);}- const json = await res.json();- if (method === "GET") {- const now = Date.now();- recentGetResponses.set(url, { data: json, expiresAt: now + GET_DEDUP_TTL_MS });- pruneRecentGetResponses(now);- }- return json as T;+ return await res.json() as T;})();if (method === "GET") {@@ -577,7 +554,8 @@ export function getPresetTimeRange(preset: "1m" | "5m" | "15m" | "30m" | "7d" | "30d" | "24h" | "today",): TimeRange {const end = new Date();- const start = new Date();+ end.setMilliseconds(0);+ const start = new Date(end);switch (preset) {case "1m":diff --git a/apps/web/lib/hooks/use-stable-time-range.ts b/apps/web/lib/hooks/use-stable-time-range.tsnew file mode 100644index 0000000..ced7d1c--- /dev/null+++ b/apps/web/lib/hooks/use-stable-time-range.ts@@ -0,0 +1,23 @@+import { useMemo } from "react";+import type { TimeRange } from "@/lib/api";++/**+ * Stabilizes a TimeRange object reference so that downstream consumers+ * (e.g. react-query keys) only see a new reference when the actual+ * start/end values change.+ */+export function useStableTimeRange(+ timeRange?: TimeRange,+ options?: { roundToMinute?: boolean },+): TimeRange | undefined {+ return useMemo<TimeRange | undefined>(() => {+ if (!timeRange?.start && !timeRange?.end) return undefined;+ const start = new Date(timeRange.start);+ const end = new Date(timeRange.end);+ if (options?.roundToMinute) {+ start.setUTCSeconds(0, 0);+ end.setUTCSeconds(0, 0);+ }+ return { start: start.toISOString(), end: end.toISOString() };+ }, [timeRange?.start, timeRange?.end, options?.roundToMinute]);+}diff --git a/apps/web/lib/query-placeholder.ts b/apps/web/lib/query-placeholder.tsnew file mode 100644index 0000000..e0292be--- /dev/null+++ b/apps/web/lib/query-placeholder.ts@@ -0,0 +1,31 @@+type IdentityValue = string | number | boolean | null;+type Identity = Record<string, IdentityValue>;++type QueryLike = {+ queryKey?: readonly unknown[];+};++function getQueryIdentityPayload(previousQuery: QueryLike | undefined): Record<string, unknown> | null {+ const payload = previousQuery?.queryKey?.[2];+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {+ return null;+ }+ return payload as Record<string, unknown>;+}++export function keepPreviousByIdentity<TData>(+ previousData: TData | undefined,+ previousQuery: QueryLike | undefined,+ identity: Identity,+): TData | undefined {+ const payload = getQueryIdentityPayload(previousQuery);+ if (!payload) return undefined;++ for (const [key, expected] of Object.entries(identity)) {+ if (payload[key] !== expected) {+ return undefined;+ }+ }++ return previousData;+}diff --git a/apps/web/lib/stats-query-keys.ts b/apps/web/lib/stats-query-keys.tsindex ed2b265..3e32d2f 100644--- a/apps/web/lib/stats-query-keys.ts+++ b/apps/web/lib/stats-query-keys.ts@@ -1,14 +1,6 @@import type { TimeRange } from "@/lib/api";-type DomainQueryParams = {- offset?: number;- limit?: number;- sortBy?: string;- sortOrder?: string;- search?: string;-};--type IPQueryParams = {+type PaginatedQueryParams = {offset?: number;limit?: number;sortBy?: string;@@ -170,7 +162,7 @@ export function getIPDomainDetailsQueryKey(export function getDomainsQueryKey(backendId?: number,- params?: DomainQueryParams,+ params?: PaginatedQueryParams,range?: TimeRange,) {return [@@ -190,7 +182,7 @@ export function getDomainsQueryKey(export function getIPsQueryKey(backendId?: number,- params?: IPQueryParams,+ params?: PaginatedQueryParams,range?: TimeRange,) {return [diff --git a/apps/web/messages/en.json b/apps/web/messages/en.jsonindex f7e6116..a14e016 100644--- a/apps/web/messages/en.json+++ b/apps/web/messages/en.json@@ -245,7 +245,9 @@"loadingChainFlow": "Loading chain flow...","showAll": "Panorama","activePolicy": "All Policies",- "noTrafficRecord": "No traffic record"+ "noTrafficRecord": "No traffic record",+ "fullscreen": "Fullscreen",+ "exitFullscreen": "Exit fullscreen"},"network": {"title": "Network",diff --git a/apps/web/messages/zh.json b/apps/web/messages/zh.jsonindex cef9571..09a45c0 100644--- a/apps/web/messages/zh.json+++ b/apps/web/messages/zh.json@@ -244,7 +244,9 @@"loadingChainFlow": "加载链路流向...","showAll": "全景展示","activePolicy": "全部策略",- "noTrafficRecord": "暂无流量记录"+ "noTrafficRecord": "暂无流量记录",+ "fullscreen": "全屏",+ "exitFullscreen": "退出全屏"},"network": {"title": "网络",diff --git a/package.json b/package.jsonindex 747d7c7..30f306a 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "clash-master",- "version": "1.1.2",+ "version": "1.1.3","private": true,"workspaces": ["apps/*",