diff --git a/src/renderer/src/runtime/sync-runtime-graph/graph-state.ts b/src/renderer/src/runtime/sync-runtime-graph/graph-state.ts index 2c8d88dfcae..7b19069414a 100644 --- a/src/renderer/src/runtime/sync-runtime-graph/graph-state.ts +++ b/src/renderer/src/runtime/sync-runtime-graph/graph-state.ts @@ -67,7 +67,6 @@ export const graphState = { cachedOpenFilesProjection: null as OpenFilesProjectionCache | null, cachedBrowserWorkspacesProjection: null as BrowserWorkspacesProjectionCache | null, cachedBrowserPagesProjection: null as BrowserPagesProjectionCache | null, - cachedMobileSessionAgentStatus: null as MobileSessionAgentStatusCache | null, cachedOpenFileIndexesSource: null as AppState['openFiles'] | null, cachedOpenFileIndexes: null as OpenFileIndexes | null, cachedEditorDraftHashes: null as EditorDraftHashCache | null, @@ -77,11 +76,22 @@ export const graphState = { hasCachedMobileTerminalTheme: false } +// Module-local rather than `graphState` fields: a nullable field on that object literal needs an +// `as` cast, which the changed-code casting gate rejects. let terminalTabOwnershipIndexCache: TerminalTabOwnershipIndex | null = null +let mobileSessionAgentStatusCache: MobileSessionAgentStatusCache | null = null + +export function getMobileSessionAgentStatusCache(): MobileSessionAgentStatusCache | null { + return mobileSessionAgentStatusCache +} + +export function setMobileSessionAgentStatusCache(cache: MobileSessionAgentStatusCache): void { + mobileSessionAgentStatusCache = cache +} export function resetRuntimeGraphSliceScanCaches(): void { terminalTabOwnershipIndexCache = null - graphState.cachedMobileSessionAgentStatus = null + mobileSessionAgentStatusCache = null } export function registeredTerminalTabKey( diff --git a/src/renderer/src/runtime/sync-runtime-graph/mobile-session-inputs.ts b/src/renderer/src/runtime/sync-runtime-graph/mobile-session-inputs.ts index 4a54beb9ef7..a96e38affe1 100644 --- a/src/renderer/src/runtime/sync-runtime-graph/mobile-session-inputs.ts +++ b/src/renderer/src/runtime/sync-runtime-graph/mobile-session-inputs.ts @@ -10,8 +10,10 @@ import { EMPTY_WORKTREE_TERMINAL_TABS, EMPTY_WORKTREE_UNIFIED_TABS, EMPTY_LAYOUT_BY_WORKTREE, + getMobileSessionAgentStatusCache, getTerminalTabOwnershipIndex, - graphState + graphState, + setMobileSessionAgentStatusCache } from './graph-state' import type { MobileSessionAgentStatusByWorktree, @@ -70,7 +72,7 @@ export function buildMobileSessionAgentStatusByWorktree( agentStatusByPaneKey: AppState['agentStatusByPaneKey'], tabsByWorktree: AppState['tabsByWorktree'] ): MobileSessionAgentStatusByWorktree { - const cached = graphState.cachedMobileSessionAgentStatus + const cached = getMobileSessionAgentStatusCache() if (cached?.agentStatusSource === agentStatusByPaneKey && cached.tabsSource === tabsByWorktree) { return cached.byWorktreeId } @@ -101,11 +103,11 @@ export function buildMobileSessionAgentStatusByWorktree( byWorktreeId.set(worktreeId, previousBucket) } } - graphState.cachedMobileSessionAgentStatus = { + setMobileSessionAgentStatusCache({ agentStatusSource: agentStatusByPaneKey, tabsSource: tabsByWorktree, byWorktreeId - } + }) return byWorktreeId }