diff --git a/js/src/hooks/use-stream-playback.ts b/js/src/hooks/use-stream-playback.ts index 5e0f7f6..7cb8758 100644 --- a/js/src/hooks/use-stream-playback.ts +++ b/js/src/hooks/use-stream-playback.ts @@ -178,12 +178,22 @@ export function useStreamPlayback( return () => clearTimeout(timeout); }, [children, streamParticle.id, streamParticle.playback_markers, userId, state.initialized]); - // --- Persist playback marker --- + // --- Persist playback marker (only advance forward, never backwards) --- + const lastPersistedMarkerRef = useRef(null); + useEffect(() => { if (!userId || !state.initialized || !currentParticle) return; + const currentTime = currentParticle.created_at; + const existingMarker = + lastPersistedMarkerRef.current ?? streamParticle.playback_markers?.[userId]; + + // Only update if advancing beyond the current marker + if (existingMarker && currentTime.getTime() <= existingMarker.getTime()) return; + + lastPersistedMarkerRef.current = currentTime; const streamDocPath = toFirestoreDocPath(path); - updateStreamPlaybackMarker(streamDocPath, userId, currentParticle.created_at); + updateStreamPlaybackMarker(streamDocPath, userId, currentTime); }, [currentParticle?.id, state.initialized, userId, path]); // --- Navigation callbacks ---