Skip to content

Commit 0438d69

Browse files
committed
fix(app): stop the auto-connect effect from cancelling itself in Strict Mode
The stored server URL was passed to connect() from inside a setTimeout, and Strict Mode's mount-cleanup-remount cycle cleared that timer before it fired. The ref guard then blocked the second attempt, so a persisted URL never reconnected in development. Calling connect() directly keeps the guard's single-attempt behaviour without the cancellable deferral.
1 parent aa7c725 commit 0438d69

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/App.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,19 @@ function App() {
7171
}
7272
}, [selectedPath]);
7373

74-
// Auto-connect on mount if we have a stored URL (once only)
74+
// Auto-connect on mount if we have a stored URL (once only). The ref guard
75+
// alone survives React Strict Mode's mount-cleanup-remount cycle in dev;
76+
// deferring the call via setTimeout previously let the Strict Mode cleanup
77+
// cancel it before it ever fired, so connect() was never actually called.
7578
useEffect(() => {
7679
if (!serverUrl || isConnected || autoConnectAttempted.current) return;
7780
autoConnectAttempted.current = true;
7881

79-
const timeoutId = setTimeout(() => {
80-
connect(serverUrl).then((success) => {
81-
if (!success) {
82-
setShowConnectionDialog(true);
83-
}
84-
});
85-
}, 0);
86-
87-
return () => clearTimeout(timeoutId);
82+
connect(serverUrl).then((success) => {
83+
if (!success) {
84+
setShowConnectionDialog(true);
85+
}
86+
});
8887
// eslint-disable-next-line react-hooks/exhaustive-deps
8988
}, []);
9089

0 commit comments

Comments
 (0)