@@ -64,20 +64,8 @@ type CachedOverview = {
6464
6565type MaMode = "v1" | "default" | "v2" ;
6666
67- function readCachedControls ( apiBase : string ) : CachedControls | null {
68- try {
69- const raw = sessionStorage . getItem ( `${ CONTROLS_CACHE_PREFIX } ${ apiBase } ` ) ;
70- if ( ! raw ) return null ;
71- return JSON . parse ( raw ) as CachedControls ;
72- } catch {
73- return null ;
74- }
75- }
76-
77- function writeCachedControls ( apiBase : string , value : CachedControls ) {
78- try {
79- sessionStorage . setItem ( `${ CONTROLS_CACHE_PREFIX } ${ apiBase } ` , JSON . stringify ( value ) ) ;
80- } catch { /* private mode / quota */ }
67+ function controlsCacheKey ( apiBase : string ) : string {
68+ return `${ CONTROLS_CACHE_PREFIX } ${ apiBase } ` ;
8169}
8270
8371export function useDashboardData ( apiBase : string ) {
@@ -86,7 +74,10 @@ export function useDashboardData(apiBase: string) {
8674 const [ selectedSection , setSelectedSection ] = useState < DashboardSection > ( readDashboardSectionFromHash ) ;
8775 const [ modelQuery , setModelQuery ] = useState ( "" ) ;
8876 const [ expandedProviders , setExpandedProviders ] = useState < Set < string > > ( new Set ( ) ) ;
89- const cachedControls = useMemo ( ( ) => readCachedControls ( apiBase ) , [ apiBase ] ) ;
77+ const cachedControls = useMemo (
78+ ( ) => readSessionListCache < CachedControls > ( controlsCacheKey ( apiBase ) ) ,
79+ [ apiBase ] ,
80+ ) ;
9081 const cachedOverview = useMemo (
9182 ( ) => readSessionListCache < CachedOverview > ( `${ OVERVIEW_CACHE_PREFIX } ${ apiBase } ` ) ,
9283 [ apiBase ] ,
@@ -281,12 +272,12 @@ export function useDashboardData(apiBase: string) {
281272 if ( ! data ) return ;
282273 if ( data . health ) {
283274 setHealth ( data . health ) ;
275+ setProviders ( data . providers ) ;
284276 writeSessionListCache ( `${ OVERVIEW_CACHE_PREFIX } ${ apiBase } ` , {
285277 health : data . health ,
286278 providers : data . providers ,
287279 } ) ;
288280 }
289- setProviders ( data . providers ) ;
290281 setError ( data . error ) ;
291282 } , [ overviewPoll . data , apiBase ] ) ;
292283
@@ -318,19 +309,19 @@ export function useDashboardData(apiBase: string) {
318309 const data = sidecarPoll . data ;
319310 if ( ! data ) return ;
320311 setSidecar ( data . sidecar ) ;
321- setShadowCall ( data . shadowCall ) ;
322- const prev = readCachedControls ( apiBase ) ?? { } ;
323- writeCachedControls ( apiBase , {
312+ if ( data . shadowCall !== undefined ) setShadowCall ( data . shadowCall ) ;
313+ const prev = readSessionListCache < CachedControls > ( controlsCacheKey ( apiBase ) ) ?? { } ;
314+ writeSessionListCache ( controlsCacheKey ( apiBase ) , {
324315 ...prev ,
325316 sidecar : data . sidecar ,
326- shadowCall : data . shadowCall ,
317+ ... ( data . shadowCall !== undefined ? { shadowCall : data . shadowCall } : { } ) ,
327318 } ) ;
328319 } , [ sidecarPoll . data , apiBase ] ) ;
329320
330321 useEffect ( ( ) => {
331322 const data = settingsPoll . data ;
332323 if ( ! data ) return ;
333- if ( data . settings ) setSettings ( data . settings ) ;
324+ if ( data . settings !== undefined ) setSettings ( data . settings ) ;
334325 // Latest-wins: only seed from settings when no newer dedicated probe has committed
335326 // while this settings poll was in flight. Always merge against the live ref.
336327 if (
@@ -342,11 +333,13 @@ export function useDashboardData(apiBase: string) {
342333 startupHealthRef . current = merged ;
343334 if ( merged ) writeSessionListCache ( `${ STARTUP_CACHE_PREFIX } ${ apiBase } ` , merged ) ;
344335 }
345- const prev = readCachedControls ( apiBase ) ?? { } ;
346- writeCachedControls ( apiBase , {
347- ...prev ,
348- settings : data . settings ?? undefined ,
349- } ) ;
336+ if ( data . settings !== undefined ) {
337+ const prev = readSessionListCache < CachedControls > ( controlsCacheKey ( apiBase ) ) ?? { } ;
338+ writeSessionListCache ( controlsCacheKey ( apiBase ) , {
339+ ...prev ,
340+ settings : data . settings ,
341+ } ) ;
342+ }
350343 } , [ settingsPoll . data , apiBase ] ) ;
351344
352345 useEffect ( ( ) => {
@@ -455,8 +448,8 @@ export function useDashboardData(apiBase: string) {
455448 } ) ;
456449 const data = await requireJson < SidecarData > ( res , "save failed" ) ;
457450 setSidecar ( { webSearch : data . webSearch , vision : data . vision } ) ;
458- const prev = readCachedControls ( apiBase ) ?? { } ;
459- writeCachedControls ( apiBase , {
451+ const prev = readSessionListCache < CachedControls > ( controlsCacheKey ( apiBase ) ) ?? { } ;
452+ writeSessionListCache ( controlsCacheKey ( apiBase ) , {
460453 ...prev ,
461454 sidecar : { webSearch : data . webSearch , vision : data . vision } ,
462455 } ) ;
0 commit comments