Merge branch 'react-dev' into 'master'
Fix issue with restoring session in React dev mode See merge request riftenlabs/lib/wizardconnect!28
This commit is contained in:
commit
dc01931ad6
1 changed files with 14 additions and 1 deletions
|
|
@ -160,11 +160,24 @@ export function useWizardConnect(
|
||||||
});
|
});
|
||||||
}, [persistSession, sessionKey, storage, startRelay]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
managerRef.current?.destroy();
|
managerRef.current?.destroy();
|
||||||
relayRef.current?.cleanup();
|
relayRef.current?.cleanup();
|
||||||
|
relayRef.current = null;
|
||||||
|
autoReconnectAttempted.current = false;
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue