Skip to content

Commit 128e445

Browse files
committed
cover watchdog cleanup, re-arm and null-ref paths
1 parent 279ccdb commit 128e445

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

packages/ui/src/shell/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function App({ devToolbar }: AppProps) {
104104
};
105105

106106
const mainRef = useRef<HTMLDivElement>(null);
107+
// Mirrors the "main" branch of renderContent() below; keep the two in sync.
107108
const showingMainApp =
108109
isBootstrapped &&
109110
isAuthenticated &&

packages/ui/src/shell/useAppVisibilityWatchdog.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,38 @@ describe("useAppVisibilityWatchdog", () => {
8181

8282
expect(captureException).not.toHaveBeenCalled();
8383
});
84+
85+
it("does not report after unmounting before the deadline", () => {
86+
const ref = { current: mountElement("0", 1200, 800) };
87+
const { unmount } = renderHook(() => useAppVisibilityWatchdog(ref, true));
88+
89+
unmount();
90+
vi.advanceTimersByTime(3000);
91+
92+
expect(captureException).not.toHaveBeenCalled();
93+
});
94+
95+
it("arms when active flips from false to true", () => {
96+
const ref = { current: mountElement("0", 1200, 800) };
97+
const { rerender } = renderHook(
98+
({ active }) => useAppVisibilityWatchdog(ref, active),
99+
{ initialProps: { active: false } },
100+
);
101+
102+
vi.advanceTimersByTime(3000);
103+
expect(captureException).not.toHaveBeenCalled();
104+
105+
rerender({ active: true });
106+
vi.advanceTimersByTime(3000);
107+
expect(captureException).toHaveBeenCalledOnce();
108+
});
109+
110+
it("does nothing when the ref never attaches", () => {
111+
const ref = { current: null };
112+
renderHook(() => useAppVisibilityWatchdog(ref, true));
113+
114+
vi.advanceTimersByTime(3000);
115+
116+
expect(captureException).not.toHaveBeenCalled();
117+
});
84118
});

0 commit comments

Comments
 (0)