Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(kg): guard matchMedia in the knowledge-graph panel mount effect (#580)

Raghav Chamadiya1b0145165252
diff --git a/packages/ui/src/c4/panels/Sidebar.tsx b/packages/ui/src/c4/panels/Sidebar.tsx
index 7e181f39b..1bf59ff7d 100644
--- a/packages/ui/src/c4/panels/Sidebar.tsx
+++ b/packages/ui/src/c4/panels/Sidebar.tsx
@@ -56,9 +56,11 @@ export function Sidebar(props: SidebarProps) {
// Collapse on small screens at first mount — a 320px overlay swallows the
// whole graph on a phone. Runs once; the user's manual toggle wins after.
+ // `matchMedia` is absent in SSR and in the jsdom test env, so guard it.
useEffect(() => {
if (
typeof window !== "undefined" &&
+ typeof window.matchMedia === "function" &&
window.matchMedia("(max-width: 767px)").matches
) {
setSidebarOpen(false);