mirror of
https://github.com/jlengrand/Maestro.git
synced 2026-03-10 08:31:19 +00:00
## CHANGES
- Eliminated mobile session ref initialization race with immediate saved defaults 🚀 - Made active tab ref mirror URL/saved tab instantly for reliable callbacks 🧭 - Simplified hook test by removing unnecessary async waiting on refs 🧪
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { renderHook, act, waitFor } from '@testing-library/react';
|
||||
import { renderHook, act } from '@testing-library/react';
|
||||
import { useMobileSessionManagement, type UseMobileSessionManagementDeps } from '../../../web/hooks/useMobileSessionManagement';
|
||||
import type { Session } from '../../../web/hooks/useSessions';
|
||||
|
||||
@@ -82,9 +82,8 @@ describe('useMobileSessionManagement', () => {
|
||||
savedActiveTabId: 'tab-1',
|
||||
}));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.activeSessionIdRef.current).toBe('session-1');
|
||||
});
|
||||
// Refs should be initialized immediately with saved values (no race condition)
|
||||
expect(result.current.activeSessionIdRef.current).toBe('session-1');
|
||||
|
||||
act(() => {
|
||||
result.current.sessionsHandlers.onSessionOutput('session-1', 'hello', 'ai', 'tab-1');
|
||||
|
||||
@@ -198,9 +198,11 @@ export function useMobileSessionManagement(
|
||||
const previousSessionStatesRef = useRef<Map<string, string>>(new Map());
|
||||
|
||||
// Ref to track activeSessionId for use in callbacks (avoids stale closure issues)
|
||||
const activeSessionIdRef = useRef<string | null>(null);
|
||||
// Initialize with same value as state to avoid race condition where WebSocket
|
||||
// messages arrive before useEffect syncs the ref
|
||||
const activeSessionIdRef = useRef<string | null>(urlSessionId || savedActiveSessionId);
|
||||
// Ref to track activeTabId for use in callbacks (avoids stale closure issues)
|
||||
const activeTabIdRef = useRef<string | null>(null);
|
||||
const activeTabIdRef = useRef<string | null>(urlTabId || savedActiveTabId);
|
||||
|
||||
// Keep activeSessionIdRef in sync with state
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user