Skip to content

Commit 432ce79

Browse files
fix(web): disable stale device settings after failed reads
1 parent 4752cfb commit 432ce79

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎apps/web/src/components/device/useDeviceControls.test.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ it("keeps actions disabled when settings cannot be confirmed after a detached co
161161
expect(controls.error).toBeNull();
162162
});
163163

164+
it("disables stale settings after a failed reopen read and recovers on a successful read", async () => {
165+
await mount();
166+
await act(async () => renderer!.update(<Probe visible={false} />));
167+
read.mockResolvedValueOnce({ _tag: "Failure", cause: "offline" });
168+
await act(async () => renderer!.update(<Probe visible />));
169+
expect(controls.detail).toBeNull();
170+
expect(controls.disabled).toBe(true);
171+
expect(controls.error).toBe("Device action failed");
172+
await act(async () => controls.act({ type: "setAppearance", value: "dark" }));
173+
expect(action).not.toHaveBeenCalled();
174+
await act(async () => renderer!.update(<Probe visible={false} />));
175+
await act(async () => renderer!.update(<Probe visible />));
176+
expect(controls.detail?.settings.appearance).toBe("light");
177+
expect(controls.disabled).toBe(false);
178+
expect(controls.error).toBeNull();
179+
});
180+
164181
it("does not let an older refresh overwrite a newer confirmed action", async () => {
165182
await mount();
166183
await act(async () => renderer!.update(<Probe visible={false} />));

‎apps/web/src/components/device/useDeviceControls.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export function useDeviceControls(options: {
5151
if (result._tag === "Success") {
5252
setDetail(result.value);
5353
setError(null);
54-
} else setError(formatEnvironmentQueryError(result.cause));
54+
} else {
55+
setDetail(null);
56+
setError(formatEnvironmentQueryError(result.cause));
57+
}
5558
});
5659
return () => {
5760
visibleRead.current = null;

0 commit comments

Comments
 (0)