Skip to content

Commit abcdccc

Browse files
fix: simplify proxy state initialization to avoid temporal dead zone
The useState initializer was trying to access userSavedProxy and proxiesResp before they were available, causing a temporal dead zone issue. Simplified to use only localStorage for initial state and let useEffect handle updates. Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
1 parent d4bab5e commit abcdccc

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

site/src/contexts/ProxyContext.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,11 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
128128
return loadUserSelectedProxy();
129129
}, [userProxyQuery.data, proxiesResp]);
130130

131-
// Load the initial state from user preferences or localStorage.
132-
// Use safe initialization to avoid temporal dead zone with userSavedProxy
133-
const [proxy, setProxy] = useState<PreferredProxy>(() => {
134-
// Only use userSavedProxy if proxiesResp is available
135-
if (proxiesResp && userSavedProxy) {
136-
return computeUsableURLS(userSavedProxy);
137-
}
138-
// Safe fallback - let useEffect handle proper initialization
139-
return computeUsableURLS(undefined);
140-
});
131+
// Load the initial state from localStorage only
132+
// Let useEffect handle proper initialization when data is available
133+
const [proxy, setProxy] = useState<PreferredProxy>(
134+
computeUsableURLS(loadUserSelectedProxy()),
135+
);
141136

142137
const { permissions } = useAuthenticated();
143138
const { metadata } = useEmbeddedMetadata();

0 commit comments

Comments
 (0)