Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix: make use local storage not trigger effects on separate tab

Scott Wilson13b75a13eb54
diff --git a/frontend/src/hooks/useLocalStorageState.ts b/frontend/src/hooks/useLocalStorageState.ts
index 2b50587eab..aee93d209d 100644
--- a/frontend/src/hooks/useLocalStorageState.ts
+++ b/frontend/src/hooks/useLocalStorageState.ts
@@ -22,8 +22,18 @@ const getLocalStorageItem = (key: string): string | null => {
};
const useLocalStorageSubscribe = (callback: (e: StorageEvent) => void) => {
- window.addEventListener("storage", callback);
- return () => window.removeEventListener("storage", callback);
+ // Only react to same-tab storage events (manually dispatched, storageArea is null).
+ // Ignore cross-tab native storage events (storageArea is set) to prevent
+ // other tabs from updating this tab's state.
+ const handler = (e: StorageEvent) => {
+ console.log("storage event", e.storageArea);
+ if (!e.storageArea) {
+ console.log("called callback");
+ callback(e);
+ }
+ };
+ window.addEventListener("storage", handler);
+ return () => window.removeEventListener("storage", handler);
};
const getLocalStorageServerSnapshot = (): never => {