Instrument persisted state hydration for perf CI debugging
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
ae27c200f1
commit
cbbfd0cf3b
2 files changed
+29
-1
No files matched your search
@@ -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;
|
||||
|
||||
+28
-1
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user