This commit is contained in:
Arjun Patel
2026-06-01 17:30:27 -07:00
parent e04010257a
commit 89b828a576
+6 -4
View File
@@ -106,9 +106,11 @@ export function useStreamPlayback(
const [state, dispatch] = useReducer(playbackReducer, initialState); const [state, dispatch] = useReducer(playbackReducer, initialState);
// Track the stream ID we've initialized for, to reset when navigating between streams // Track the stream ID we've initialized for, to reset when navigating between streams
const initializedForRef = useRef<string | null>(null); const initializedForRef = useRef<string | null>(null);
// Latest currentIndex for onParticleRemoved (passed to the subscription), so // Latest currentIndex for onParticleRemoved, which is passed into
// it reads the current value without re-subscribing. useEffectEvent can't be // useLiveParticleChildren. Reading it through a ref keeps the callback stable
// used — it may not be passed to another hook. // (no re-subscription) and breaks the declaration cycle
// children -> currentIndex -> callback -> children. useEffectEvent can't be
// used here — Effect Events may not be passed to another hook.
const currentIndexRef = useRef(0); const currentIndexRef = useRef(0);
// --- Firestore change callbacks --- // --- Firestore change callbacks ---
@@ -147,7 +149,7 @@ export function useStreamPlayback(
const currentParticle = currentIndex !== -1 ? children[currentIndex] : null; const currentParticle = currentIndex !== -1 ? children[currentIndex] : null;
// Keep the latest-index ref in sync for onParticleRemoved (above). // Keep the ref read by onParticleRemoved in sync with the derived index.
useEffect(() => { useEffect(() => {
currentIndexRef.current = currentIndex; currentIndexRef.current = currentIndex;
}, [currentIndex]); }, [currentIndex]);