Jon/keyed browser session id cache (#2928)

This commit is contained in:
Jonathan Dobson
2025-07-10 18:51:45 -04:00
committed by GitHub
parent c294f338d0
commit 1f795a7d95
3 changed files with 148 additions and 78 deletions

View File

@@ -1,6 +1,5 @@
import React, { createContext, useMemo } from "react";
import { useLocation } from "react-router-dom";
import { lsKeys } from "@/util/env";
function useIsDebugMode() {
const location = useLocation();
@@ -10,23 +9,8 @@ function useIsDebugMode() {
);
}
function getCurrentBrowserSessionId() {
const stored = localStorage.getItem(lsKeys.optimisticBrowserSession);
let browserSessionId: string | null = null;
try {
const parsed = JSON.parse(stored ?? "");
const { browser_session_id } = parsed;
browserSessionId = browser_session_id as string;
} catch {
// pass
}
return browserSessionId;
}
export type DebugStoreContextType = {
isDebugMode: boolean;
getCurrentBrowserSessionId: () => string | null;
};
export const DebugStoreContext = createContext<
@@ -39,9 +23,7 @@ export const DebugStoreProvider: React.FC<{ children: React.ReactNode }> = ({
const isDebugMode = useIsDebugMode();
return (
<DebugStoreContext.Provider
value={{ isDebugMode, getCurrentBrowserSessionId }}
>
<DebugStoreContext.Provider value={{ isDebugMode }}>
{children}
</DebugStoreContext.Provider>
);