@@ -108,16 +108,17 @@ export default function ProviderWorkspaceShell({
108108 const [ modelsLoadFailed , setModelsLoadFailed ] = useState ( false ) ;
109109 const quotasCacheKey = `ocx.providers.quotas.v1:${ apiBase } ` ;
110110 const usageCacheKey = `ocx.providers.usage.v1:${ apiBase } ` ;
111- const cachedQuotas = readSessionListCache < Record < string , ProviderQuotaReportView > > ( quotasCacheKey ) ;
112- const cachedUsage = readSessionListCache < {
113- totals : Record < string , ProviderUsageTotals > ;
114- models : Record < string , ProviderModelUsageRow [ ] > ;
115- } > ( usageCacheKey ) ;
116- const [ usageTotals , setUsageTotals ] = useState < Record < string , ProviderUsageTotals > > ( ( ) => cachedUsage ?. totals ?? { } ) ;
117- const [ usageModels , setUsageModels ] = useState < Record < string , ProviderModelUsageRow [ ] > > ( ( ) => cachedUsage ?. models ?? { } ) ;
118- const [ quotaReports , setQuotaReports ] = useState < Record < string , ProviderQuotaReportView > > ( ( ) => cachedQuotas ?? { } ) ;
119- const [ usageLoading , setUsageLoading ] = useState ( ( ) => ! cachedUsage ) ;
120- const [ quotasLoading , setQuotasLoading ] = useState ( ( ) => ! cachedQuotas ) ;
111+ const [ usageTotals , setUsageTotals ] = useState < Record < string , ProviderUsageTotals > > ( ( ) => (
112+ readSessionListCache < { totals : Record < string , ProviderUsageTotals > } > ( usageCacheKey ) ?. totals ?? { }
113+ ) ) ;
114+ const [ usageModels , setUsageModels ] = useState < Record < string , ProviderModelUsageRow [ ] > > ( ( ) => (
115+ readSessionListCache < { models : Record < string , ProviderModelUsageRow [ ] > } > ( usageCacheKey ) ?. models ?? { }
116+ ) ) ;
117+ const [ quotaReports , setQuotaReports ] = useState < Record < string , ProviderQuotaReportView > > ( ( ) => (
118+ readSessionListCache < Record < string , ProviderQuotaReportView > > ( quotasCacheKey ) ?? { }
119+ ) ) ;
120+ const [ usageLoading , setUsageLoading ] = useState ( ( ) => ! readSessionListCache ( usageCacheKey ) ) ;
121+ const [ quotasLoading , setQuotasLoading ] = useState ( ( ) => ! readSessionListCache ( quotasCacheKey ) ) ;
121122 const [ modelsLoadEpoch , setModelsLoadEpoch ] = useState ( 0 ) ;
122123 const filterWrapRef = useRef < HTMLDivElement > ( null ) ;
123124
@@ -164,7 +165,9 @@ export default function ProviderWorkspaceShell({
164165 let cancelled = false ;
165166 const timeout = window . setTimeout ( ( ) => {
166167 // Keep last-good paint when sessionStorage already seeded — don't flash loading skeletons.
167- if ( ! cachedUsage ) setUsageLoading ( true ) ;
168+ // Read inside the effect (keyed by usageCacheKey) so the seed check stays correct without
169+ // closing over an unstable cachedUsage render value.
170+ if ( ! readSessionListCache ( usageCacheKey ) ) setUsageLoading ( true ) ;
168171 void fetch ( `${ apiBase } /api/usage?range=30d` )
169172 . then ( r => readJsonIfOk < {
170173 providers ?: Array < { provider : string ; requests : number ; totalTokens ?: number } > ;
@@ -206,7 +209,7 @@ export default function ProviderWorkspaceShell({
206209 useEffect ( ( ) => {
207210 let cancelled = false ;
208211 const timeout = window . setTimeout ( ( ) => {
209- if ( ! cachedQuotas ) setQuotasLoading ( true ) ;
212+ if ( ! readSessionListCache ( quotasCacheKey ) ) setQuotasLoading ( true ) ;
210213 void fetch ( `${ apiBase } /api/provider-quotas` )
211214 . then ( r => readJsonIfOk < { reports ?: Array < { provider : string ; label ?: string ; source ?: string ; updatedAt ?: number ; quota ?: unknown } > } > ( r ) )
212215 . then ( ( data ) => {
0 commit comments