From c8808ee3b2fb1da032a7fb2c1c260e625fec97c4 Mon Sep 17 00:00:00 2001 From: Alex P Date: Sat, 18 Oct 2025 00:30:45 +0300 Subject: [PATCH] fix: resolve React hooks violation in hardware settings Moved getVideoSleepMode useEffect before early returns to comply with React Rules of Hooks. All hooks must be called in the same order on every component render, before any conditional returns. This completes the merge from dev branch, preserving both: - Permission-based access control from multi-session branch - HDMI sleep mode power saving feature from dev branch --- .../routes/devices.$id.settings.hardware.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ui/src/routes/devices.$id.settings.hardware.tsx b/ui/src/routes/devices.$id.settings.hardware.tsx index 80dcab5e..236c854f 100644 --- a/ui/src/routes/devices.$id.settings.hardware.tsx +++ b/ui/src/routes/devices.$id.settings.hardware.tsx @@ -94,6 +94,17 @@ export default function SettingsHardwareRoute() { } }, [send, setBacklightSettings, isLoading, permissions]); + useEffect(() => { + send("getVideoSleepMode", {}, (resp: JsonRpcResponse) => { + if ("error" in resp) { + console.error("Failed to get power saving mode:", resp.error); + return; + } + const result = resp.result as { enabled: boolean; duration: number }; + setPowerSavingEnabled(result.duration >= 0); + }); + }, [send]); + // Return early if permissions are loading if (isLoading) { return ( @@ -112,17 +123,6 @@ export default function SettingsHardwareRoute() { ); } - useEffect(() => { - send("getVideoSleepMode", {}, (resp: JsonRpcResponse) => { - if ("error" in resp) { - console.error("Failed to get power saving mode:", resp.error); - return; - } - const result = resp.result as { enabled: boolean; duration: number }; - setPowerSavingEnabled(result.duration >= 0); - }); - }, [send]); - return (