Fix issue with restoring session in React dev mode

This commit is contained in:
Dagur Valberg Johannsson 2026-05-09 20:25:45 +02:00
parent e71f76c1d0
commit c2b13102b9
No known key found for this signature in database
GPG key ID: FD701804AEE88107

View file

@ -160,11 +160,24 @@ export function useWizardConnect(
});
}, [persistSession, sessionKey, storage, startRelay]);
// Cleanup on unmount
// Cleanup on unmount.
//
// Reset `autoReconnectAttempted` here so React 18 StrictMode's dev-mode
// mount→unmount→remount cycle doesn't leave the hook in a "attempted but
// torn down" state. Without the reset:
// - Mount A: auto-reconnect fires, creates relay, ref → true.
// - StrictMode cleanup: relay destroyed.
// - Mount B: auto-reconnect sees ref === true, skips. No new relay.
// Result: a stored session never reconnects in dev. Resetting the ref on
// cleanup lets Mount B re-fire the auto-reconnect path and rebuild the
// relay. In production (no StrictMode) this only runs at real unmount, so
// the reset is harmless there.
useEffect(() => {
return () => {
managerRef.current?.destroy();
relayRef.current?.cleanup();
relayRef.current = null;
autoReconnectAttempted.current = false;
};
}, []);