diff --git a/packages/react/src/hooks/useWizardConnect.ts b/packages/react/src/hooks/useWizardConnect.ts index ea19202..aae0a14 100644 --- a/packages/react/src/hooks/useWizardConnect.ts +++ b/packages/react/src/hooks/useWizardConnect.ts @@ -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; }; }, []);