Fix issue with restoring session in React dev mode
This commit is contained in:
parent
e71f76c1d0
commit
c2b13102b9
1 changed files with 14 additions and 1 deletions
|
|
@ -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;
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue