fix: address PR review findings
- WidgetCacheAge reads from query cache on every tick (reactive) - Guard empty timestamps array (no -Infinity edge case) - Docker widget: add explicit refetchInterval (not under [["widget"]]) - system-resources: split integrationIds reset into separate effect - Remove unused React import in vpn widget
This commit is contained in:
4 files changed
+27
-26
No files matched your search
@@ -184,7 +184,9 @@ export default function DockerWidget({ options, width, isEditMode }: WidgetCompo
|
||||
const t = useScopedI18n("docker");
|
||||
const isTiny = width <= 256;
|
||||
|
||||
const { data } = clientApi.docker.getContainers.useQuery(undefined);
|
||||
const { data } = clientApi.docker.getContainers.useQuery(undefined, {
|
||||
refetchInterval: 30_000,
|
||||
});
|
||||
const containers = data?.containers ?? [];
|
||||
const timestamp = useMemo(() => data?.timestamp ?? new Date(), [data?.timestamp]);
|
||||
const relativeTime = useTimeAgo(timestamp);
|
||||
|
||||
@@ -43,21 +43,21 @@ export default function SystemResources({ integrationIds, options }: WidgetCompo
|
||||
{ cpu: number; memory: number; gpu: number; network: { up: number; down: number } | null }[]
|
||||
>(() => (data[0] ? [toChartItem(data[0].healthInfo)] : []));
|
||||
|
||||
const lastUpdatedAt = useRef(dataUpdatedAt);
|
||||
const prevIntegrationIds = useRef(integrationIds);
|
||||
useEffect(() => {
|
||||
if (prevIntegrationIds.current === integrationIds) return;
|
||||
prevIntegrationIds.current = integrationIds;
|
||||
setItems([]);
|
||||
}, [integrationIds]);
|
||||
|
||||
const lastUpdatedAt = useRef(dataUpdatedAt);
|
||||
useEffect(() => {
|
||||
if (dataUpdatedAt === lastUpdatedAt.current) return;
|
||||
lastUpdatedAt.current = dataUpdatedAt;
|
||||
const firstItem = data[0];
|
||||
if (!firstItem) return;
|
||||
const idsChanged = prevIntegrationIds.current !== integrationIds;
|
||||
prevIntegrationIds.current = integrationIds;
|
||||
setItems((prev) =>
|
||||
idsChanged
|
||||
? [toChartItem(firstItem.healthInfo)]
|
||||
: [...prev, toChartItem(firstItem.healthInfo)].slice(-MAX_QUEUE_SIZE),
|
||||
);
|
||||
}, [dataUpdatedAt, data, integrationIds]);
|
||||
setItems((prev) => [...prev, toChartItem(firstItem.healthInfo)].slice(-MAX_QUEUE_SIZE));
|
||||
}, [dataUpdatedAt, data]);
|
||||
|
||||
const showNetwork =
|
||||
items.length === 0 || (items.every((item) => item.network !== null) && options.visibleCharts.includes("network"));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { Flex, ScrollArea, Stack } from "@mantine/core";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
|
||||
Reference in new issue
Block a user