@@ -49,6 +49,7 @@ const useChat = () => {
4949 currentSessionId,
5050 currentSession,
5151 } = useChatHistory ( ) ;
52+ const [ hasHydrated , setHasHydrated ] = useState ( false ) ;
5253
5354 // State machine for chat lifecycle
5455 const machineRef = useRef < ReturnType < typeof createChatStateMachine > > ( createChatStateMachine ( ) ) ;
@@ -123,6 +124,10 @@ What would you like to do today? I'm here to make your XLM-to-fiat journey smoot
123124 const queuedSendsRef = useRef < QueuedSend [ ] > ( [ ] ) ;
124125 const replayingQueueRef = useRef ( false ) ;
125126
127+ useEffect ( ( ) => {
128+ setHasHydrated ( true ) ;
129+ } , [ ] ) ;
130+
126131 useEffect ( ( ) => {
127132 messagesRef . current = messages ;
128133 } , [ messages ] ) ;
@@ -162,6 +167,7 @@ What would you like to do today? I'm here to make your XLM-to-fiat journey smoot
162167
163168 // Initialize chat session
164169 useEffect ( ( ) => {
170+ if ( ! hasHydrated ) return ;
165171 const machine = machineRef . current ;
166172 const machineState = machine . getState ( ) ;
167173
@@ -175,7 +181,7 @@ What would you like to do today? I'm here to make your XLM-to-fiat journey smoot
175181 machine . transition ( ChatEvent . INITIALIZE_SESSION ) ;
176182 }
177183 }
178- } , [ currentSession , currentSessionId , createNewSession ] ) ;
184+ } , [ currentSession , currentSessionId , createNewSession , hasHydrated ] ) ;
179185
180186 // Persist messages to session
181187 useEffect ( ( ) => {
@@ -645,6 +651,7 @@ What would you like to do today? I'm here to make your XLM-to-fiat journey smoot
645651
646652 // Update suggested actions when wallet connection changes
647653 useEffect ( ( ) => {
654+ if ( ! hasHydrated ) return ;
648655 const machine = machineRef . current ;
649656 if ( machine . getState ( ) . state !== ChatState . UNINITIALIZED ) {
650657 setMessages ( ( prevMessages : ChatMessage [ ] ) => {
@@ -662,7 +669,7 @@ What would you like to do today? I'm here to make your XLM-to-fiat journey smoot
662669 return prevMessages ;
663670 } ) ;
664671 }
665- } , [ connection . isConnected , getInitialSuggestedActions ] ) ;
672+ } , [ connection . isConnected , getInitialSuggestedActions , hasHydrated ] ) ;
666673
667674 // Derive conversationState from machine for backward compatibility
668675 const conversationState = useMemo ( ( ) : ConversationState => {
0 commit comments