Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb63624f

Browse files
fix: restore original proxy selection logic with auto-selection useEffect
Restore the original two-phase proxy selection approach:1. updateProxy with autoSelectBasedOnLatency=false for stable updates2. Separate useEffect for auto-selection that saves to localStorageThis fixes the test failures by ensuring latency-based selection workswhen no user proxy is saved, matching the original behavior.Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
1 parent5fbc42d commitb63624f

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

‎site/src/contexts/ProxyContext.tsx

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,53 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
165165
// updateProxy is a helper function that when called will
166166
// update the proxy being used.
167167
constupdateProxy=useCallback(()=>{
168-
// Use latency-based selection if no user proxy is saved
169-
// Only skip latency selection if we have a saved proxy or latencies aren't loaded yet
170-
constshouldUseLatency=!userSavedProxy;
171168
setProxy(
172169
getPreferredProxy(
173170
proxiesResp??[],
174171
userSavedProxy,
175-
latenciesLoaded ?proxyLatencies :undefined,
176-
shouldUseLatency,
172+
proxyLatencies,
173+
// Do not auto select based on latencies, as inconsistent latencies can cause this
174+
// to change on each call. updateProxy should be stable when selecting a proxy to
175+
// prevent flickering.
176+
false,
177177
),
178178
);
179-
},[proxiesResp,proxyLatencies,userSavedProxy,latenciesLoaded]);
179+
},[proxiesResp,proxyLatencies,userSavedProxy]);
180180

181181
// This useEffect ensures the proxy to be used is updated whenever the state changes.
182182
// This includes proxies being loaded, latencies being calculated, and the user selecting a proxy.
183183
// biome-ignore lint/correctness/useExhaustiveDependencies: Only update if the source data changes
184184
useEffect(()=>{
185185
updateProxy();
186-
},[proxiesResp,proxyLatencies,userSavedProxy,latenciesLoaded]);
186+
},[proxiesResp,proxyLatencies,userSavedProxy]);
187187

188+
// This useEffect will auto select the best proxy if the user has not selected one.
189+
// It must wait until all latencies are loaded to select based on latency. This does mean
190+
// the first time a user loads the page, the proxy will "flicker" to the best proxy.
191+
//
192+
// Once the page is loaded, or the user selects a proxy, this will not run again.
193+
// biome-ignore lint/correctness/useExhaustiveDependencies: Only update if the source data changes
194+
useEffect(()=>{
195+
if(userSavedProxy!==undefined){
196+
return;// User has selected a proxy, do not auto select.
197+
}
198+
if(!latenciesLoaded){
199+
// Wait until the latencies are loaded first.
200+
return;
201+
}
202+
203+
constbest=getPreferredProxy(
204+
proxiesResp??[],
205+
userSavedProxy,
206+
proxyLatencies,
207+
true,
208+
);
188209

210+
if(best?.proxy){
211+
saveUserSelectedProxy(best.proxy);
212+
updateProxy();
213+
}
214+
},[latenciesLoaded,proxiesResp,proxyLatencies]);
189215

190216
return(
191217
<ProxyContext.Provider

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp