Fix 100% browser CPU on live dashboard caused by unstable SWR default

The `= {}` destructuring default in useDeferredStreamMetadata created a
new object reference every render while the SWR key was null (during the
2-second defer delay). This triggered an infinite re-render loop through
useCameraLiveMode's useEffect dependency on streamMetadata.

Replace with a module-level EMPTY_METADATA constant for referential
stability.

Upstream bug introduced in #21072 (97b29d17).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Eric W 2026-03-26 19:55:12 -04:00
parent 01392e03ac
commit 4123acda00

View File

@ -5,6 +5,7 @@ import { LiveStreamMetadata } from "@/types/live";
const FETCH_TIMEOUT_MS = 10000; const FETCH_TIMEOUT_MS = 10000;
const DEFER_DELAY_MS = 2000; const DEFER_DELAY_MS = 2000;
const EMPTY_METADATA: { [key: string]: LiveStreamMetadata } = {};
/** /**
* Hook that fetches go2rtc stream metadata with deferred loading. * Hook that fetches go2rtc stream metadata with deferred loading.
@ -77,7 +78,7 @@ export default function useDeferredStreamMetadata(streamNames: string[]) {
return metadata; return metadata;
}, []); }, []);
const { data: metadata = {} } = useSWR<{ const { data: metadata = EMPTY_METADATA } = useSWR<{
[key: string]: LiveStreamMetadata; [key: string]: LiveStreamMetadata;
}>(swrKey, fetcher, { }>(swrKey, fetcher, {
revalidateOnFocus: false, revalidateOnFocus: false,