diff --git a/apps/desktop/src/desktopPerfAutomation.ts b/apps/desktop/src/desktopPerfAutomation.ts index f79685fdcb..06d0830e0b 100644 --- a/apps/desktop/src/desktopPerfAutomation.ts +++ b/apps/desktop/src/desktopPerfAutomation.ts @@ -409,6 +409,7 @@ async function seedRendererState( const script = ` (() => { const key = "t3code:renderer-state:v7"; + localStorage.setItem("t3code:perf-debug", "1"); localStorage.setItem(key, JSON.stringify(${JSON.stringify(state)})); let projects = -1; let threads = -1; diff --git a/apps/web/src/store.ts b/apps/web/src/store.ts index 6b38d7b007..a686aad189 100644 --- a/apps/web/src/store.ts +++ b/apps/web/src/store.ts @@ -101,6 +101,8 @@ const initialState: AppState = { function readPersistedState(): AppState { if (typeof window === "undefined") return initialState; + const perfDebugEnabled = window.localStorage.getItem("t3code:perf-debug") === "1"; + try { const rawCurrent = window.localStorage.getItem(PERSISTED_STATE_KEY); const legacyValues = LEGACY_PERSISTED_STATE_KEYS.map((key) => window.localStorage.getItem(key)); @@ -109,7 +111,21 @@ function readPersistedState(): AppState { if (!raw) return initialState; const rawCodethingV1 = window.localStorage.getItem("codething:renderer-state:v1"); const hydrated = hydratePersistedState(raw, !rawCurrent && raw === rawCodethingV1); - if (!hydrated) return initialState; + if (!hydrated) { + if (perfDebugEnabled) { + console.info("[perf-debug] hydratePersistedState returned null", { + rawLength: raw.length, + hasCurrent: rawCurrent !== null, + }); + } + return initialState; + } + if (perfDebugEnabled) { + console.info("[perf-debug] hydrated persisted state", { + projects: hydrated.projects.length, + threads: hydrated.threads.length, + }); + } const threads = hydrated.threads.map((thread) => normalizeThreadTerminals(thread)); const activeThreadId = threads.some((thread) => thread.id === hydrated.activeThreadId) @@ -118,6 +134,9 @@ function readPersistedState(): AppState { return { ...hydrated, threads, activeThreadId, diffOpen: false }; } catch { + if (perfDebugEnabled) { + console.info("[perf-debug] readPersistedState threw; falling back to initial state"); + } return initialState; } } @@ -126,6 +145,14 @@ function persistState(state: AppState): void { if (typeof window === "undefined") return; try { + const perfDebugEnabled = window.localStorage.getItem("t3code:perf-debug") === "1"; + if (perfDebugEnabled) { + console.info("[perf-debug] persistState", { + projects: state.projects.length, + threads: state.threads.length, + activeThreadId: state.activeThreadId, + }); + } window.localStorage.setItem(PERSISTED_STATE_KEY, JSON.stringify(toPersistedState(state))); for (const legacyKey of LEGACY_PERSISTED_STATE_KEYS) { window.localStorage.removeItem(legacyKey);