fix: address PR review — bugs, dead code, error handling
Critical fixes:
- Smart Home: invalidate entity state query after toggle mutation
- Beszel live mode: use 5s refetchInterval instead of global 30s
- Fix unit test assertions for 5-arg setQueryCacheAsync signature
- Fix serialize/deserialize mismatch: JSON.parse on read (matches persister's JSON.stringify)
- Remove render-time setActiveQueryCacheBoardId race (keep only useEffect)
Error handling:
- Log persistence errors instead of swallowing with catch(() => {})
- Log QueryCacheHydration failures with ErrorWithMetadata
- Beszel: log partial failures (system details, container stats)
Dead code removal:
- Remove dead queryKey from all 39 request handlers + lib files
- Delete unused Redis APIs: createCacheChannel, createChannelWithLatestAndEvents,
createChannelEventHistory, history-channel.ts
- Remove stale createCacheChannel mock from docker test
Cleanup:
- Seed system-resources chart from initial query data (no empty start)
- Remove redundant refetchOnWindowFocus/refetchOnReconnect from BoardProvider
This commit is contained in:
50 files changed
+31
-254
No files matched your search
@@ -1,24 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
|
||||
export const useLiveStats = (integrationIds: string[], systemId: string, enabled: boolean) => {
|
||||
const queryInput = useMemo(
|
||||
() => ({
|
||||
integrationIds,
|
||||
systemId,
|
||||
timePeriod: "1m" as const,
|
||||
includeDocker: true,
|
||||
}),
|
||||
[integrationIds, systemId],
|
||||
const { data, error } = clientApi.widget.beszel.getSystemStats.useQuery(
|
||||
{ integrationIds, systemId, timePeriod: "1m" as const, includeDocker: true },
|
||||
{ enabled: enabled && systemId !== "", refetchInterval: 5_000 },
|
||||
);
|
||||
|
||||
const { data, error } = clientApi.widget.beszel.getSystemStats.useQuery(queryInput, {
|
||||
enabled: enabled && systemId !== "",
|
||||
});
|
||||
|
||||
return {
|
||||
data: data ? { systemStats: data.systemStats, containerStats: data.containerStats } : null,
|
||||
error: error ?? (data?.error ? new Error(data.error) : null),
|
||||
|
||||
@@ -25,7 +25,10 @@ export default function SmartHomeEntityStateWidget({
|
||||
};
|
||||
const { data: entityState } = clientApi.widget.smartHome.entityState.useQuery(input);
|
||||
|
||||
const { mutate } = clientApi.widget.smartHome.switchEntity.useMutation();
|
||||
const utils = clientApi.useUtils();
|
||||
const { mutate } = clientApi.widget.smartHome.switchEntity.useMutation({
|
||||
onSettled: () => void utils.widget.smartHome.entityState.invalidate(input),
|
||||
});
|
||||
|
||||
const attribute = options.entityUnit.length > 0 ? " " + options.entityUnit : "";
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export default function SystemResources({ integrationIds, options }: WidgetCompo
|
||||
|
||||
const [items, setItems] = useState<
|
||||
{ cpu: number; memory: number; gpu: number; network: { up: number; down: number } | null }[]
|
||||
>([]);
|
||||
>(() => (data[0] ? [toChartItem(data[0].healthInfo)] : []));
|
||||
|
||||
useEffect(() => {
|
||||
const firstItem = data[0];
|
||||
|
||||
Reference in new issue
Block a user