Skip to content

Commit ffbeed9

Browse files
fix: use useState for userSavedProxy to make it reactive
- Change userSavedProxy from useMemo to useState to make it reactive to changes - Update setUserSavedProxy when auto-selecting proxy or manually setting/clearing - This ensures userProxy in context reflects current localStorage state - Matches main branch behavior where userSavedProxy was a useState Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
1 parent 8c2b457 commit ffbeed9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

site/src/contexts/ProxyContext.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ export const ProxyContext = createContext<ProxyContextValue | undefined>(
9393
export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
9494
const queryClient = useQueryClient();
9595

96-
// Get user saved proxy from localStorage
97-
const userSavedProxy = useMemo(() => {
98-
return loadUserSelectedProxy();
99-
}, []);
96+
// Using a useState so the caller always has the latest user saved
97+
// proxy.
98+
const [userSavedProxy, setUserSavedProxy] = useState(loadUserSelectedProxy());
10099

101100
// Load the initial state from localStorage only
102101
// Let useEffect handle proper initialization when data is available
@@ -182,6 +181,7 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
182181

183182
if (best?.proxy) {
184183
saveUserSelectedProxy(best.proxy);
184+
setUserSavedProxy(best.proxy);
185185
updateProxy();
186186
}
187187
}, [latenciesLoaded, proxiesResp, proxyLatencies]);
@@ -203,12 +203,14 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
203203
setProxy: (proxy: Region) => {
204204
// Save to localStorage
205205
saveUserSelectedProxy(proxy);
206+
setUserSavedProxy(proxy);
206207
// Update the selected proxy
207208
updateProxy();
208209
},
209210
clearProxy: () => {
210211
// Clear from localStorage
211212
clearUserSelectedProxy();
213+
setUserSavedProxy(undefined);
212214
updateProxy();
213215
},
214216
}}

0 commit comments

Comments
 (0)