fix(traffic): дождаться каталога перед запросами выбранного сервера

This commit is contained in:
Denozordec committed 2026-10-11 13:10:37 +07:00
1 parent b619ef208e
commit 59938118bd
9 files changed
+194 -18

No files matched your search

+11 -5
View File
@@ -787,6 +787,11 @@ export default function TrafficPage() {
const trafficLoading = trafficState?.key !== trafficKey
const trafficError = trafficState?.key === trafficKey ? trafficState.error : undefined
const [liveServers, setLiveServers] = useState<ServerTraffic[]>([])
const trafficSourceKey = JSON.stringify([isLive, backendUrl])
const [liveServerOwner, setLiveServerOwner] = useState<string | null>(null)
const confirmedLiveServer = isLive && liveServerOwner === trafficSourceKey
&& /^[1-9]\d*$/.test(selectedId) && Number.isSafeInteger(Number(selectedId))
&& liveServers.some(server => server.id === selectedId)
const [serverIfaces, setServerIfaces] = useState<LiveTrafficInterface[]>([])
const [selectedIface, setSelectedIface] = useState("__all__")
const [hideDisabledIfaces, setHideDisabledIfaces] = useState(true)
@@ -822,7 +827,7 @@ export default function TrafficPage() {
const currentDetail = detailResult?.key === detailKey ? detailResult : null
const detailBusy = isLive && effectiveMode === "servers" && Boolean(selectedId) && currentDetail === null
const { sample: liveSample, error: liveStreamError, receivedAt: liveReceivedAt } = useTrafficLive({
enabled: isLive && effectiveMode === "servers" && liveServers.some((s) => s.id === selectedId),
enabled: confirmedLiveServer && effectiveMode === "servers",
backendUrl,
serverId: selectedId,
iface: selectedIface,
@@ -860,6 +865,7 @@ export default function TrafficPage() {
})
const mappedUsers = usersRes.users.map(toLiveUser)
setLiveServers(mapped)
setLiveServerOwner(JSON.stringify([isLive, backendUrl]))
setLiveUsers(mappedUsers)
setLiveBoundIfaces(liveIfaces)
setTrafficState({ key, status: "ready", receivedAt: Date.now() })
@@ -941,7 +947,7 @@ export default function TrafficPage() {
)
useEffect(() => {
if (!isLive || effectiveMode !== "servers" || !selectedId) {
if (!confirmedLiveServer || effectiveMode !== "servers") {
// eslint-disable-next-line react-hooks/set-state-in-effect
setServerIfaces([])
setSelectedIface("__all__")
@@ -954,10 +960,10 @@ export default function TrafficPage() {
.then((res) => { if (!cancelled) setServerIfaces(res.interfaces) })
.catch(() => { if (!cancelled) setServerIfaces([]) })
return () => { cancelled = true }
}, [isLive, selectedId, effectiveMode, apiFetch])
}, [confirmedLiveServer, selectedId, effectiveMode, apiFetch])
useEffect(() => {
if (!isLive || effectiveMode !== "servers" || !selectedId) {
if (!confirmedLiveServer || effectiveMode !== "servers") {
return
}
let cancelled = false
@@ -973,7 +979,7 @@ export default function TrafficPage() {
if (!cancelled) setDetailResult({ key: detailKey, server: null, error: error instanceof Error ? error.message : "Не удалось загрузить детали трафика" })
})
return () => { cancelled = true }
}, [isLive, effectiveMode, selectedId, range, selectedIface, apiFetch, liveBoundIfaces, detailKey])
}, [confirmedLiveServer, effectiveMode, selectedId, range, selectedIface, apiFetch, liveBoundIfaces, detailKey])
const handleModeChange = (next: GroupMode) => {
setGroupMode(next)