@dbcdk/react-components 0.0.80 → 0.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,13 +2,6 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import { nestedFiltering } from '../../../utils/arrays/nested-filtering';
5
- /**
6
- * Production notes:
7
- * - No console logging.
8
- * - Auto-expands the correct expandable chain for the active link (including when the active link
9
- * points to the expandable parent itself).
10
- * - Normalizes hrefs (trailing slashes) so comparisons are stable.
11
- */
12
5
  const hasChildren = (item) => Array.isArray(item.children) && item.children.length > 0;
13
6
  const hasHref = (item) => typeof item.href === 'string' && item.href.length > 0;
14
7
  const normalizeHref = (href) => {
@@ -86,24 +79,23 @@ export function SidebarProvider({ children, items, initialQuery, initialCollapse
86
79
  useEffect(() => {
87
80
  itemsRef.current = items;
88
81
  }, [items]);
89
- const [isSidebarCollapsed, setSidebarCollapsed] = useState(() => {
90
- if (typeof window === 'undefined')
91
- return initialSidebarCollapsed !== null && initialSidebarCollapsed !== void 0 ? initialSidebarCollapsed : false;
92
- if (initialSidebarCollapsed !== undefined) {
93
- return initialSidebarCollapsed;
94
- }
82
+ const [isSidebarCollapsed, setSidebarCollapsed] = useState(initialSidebarCollapsed !== null && initialSidebarCollapsed !== void 0 ? initialSidebarCollapsed : false);
83
+ // Runs once after hydration — safe to read localStorage and window.innerWidth here.
84
+ useEffect(() => {
85
+ if (initialSidebarCollapsed !== undefined)
86
+ return;
95
87
  try {
96
88
  const stored = window.localStorage.getItem(SIDEBAR_COLLAPSED_STORAGE_KEY);
97
89
  if (stored !== null) {
98
- const parsed = JSON.parse(stored);
99
- return Boolean(parsed);
90
+ setSidebarCollapsed(Boolean(JSON.parse(stored))); // eslint-disable-line react-hooks/set-state-in-effect -- intentional: SSR-safe initial read
91
+ return;
100
92
  }
101
93
  }
102
94
  catch {
103
95
  // ignore parse failures
104
96
  }
105
- return getBreakpoint(window.innerWidth) === 'small';
106
- });
97
+ setSidebarCollapsed(getBreakpoint(window.innerWidth) === 'small');
98
+ }, []); // intentionally empty — only runs once after first mount
107
99
  const triggerExpandAll = useCallback(() => setDefaultExpanded(true), []);
108
100
  const resetExpandAll = useCallback(() => setDefaultExpanded(null), []);
109
101
  const setActiveLink = useCallback((href) => setActiveHref(href), []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.80",
3
+ "version": "0.0.81",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",