Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: timeline showing 2 current bars — use WeakMap keyed by frame object

Louis Beaumontbcce42796e98
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
index 8b1794c07..fa6123761 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
@@ -463,12 +463,12 @@ export const TimelineSlider = ({
}, [zoomLevel]);
- // Pre-compute frame index map for O(1) lookups instead of O(n) indexOf
- // This reduces 2.68M comparisons per render to just 400 Map lookups
+ // Pre-compute frame index map for O(1) lookups instead of O(n) indexOf.
+ // Uses object identity (WeakMap) so duplicate timestamps don't collide.
const frameIndexMap = useMemo(() => {
- const map = new Map<string, number>();
+ const map = new WeakMap<StreamTimeSeriesResponse, number>();
frames.forEach((frame, index) => {
- map.set(frame.timestamp, index);
+ map.set(frame, index);
});
return map;
}, [frames]);
@@ -1489,8 +1489,8 @@ export const TimelineSlider = ({
)}
{group.frames.map((frame, frameIdx) => {
- // O(1) lookup instead of O(n) indexOf
- const frameIndex = frameIndexMap.get(frame.timestamp) ?? -1;
+ // O(1) lookup via object identity (WeakMap)
+ const frameIndex = frameIndexMap.get(frame) ?? -1;
const isSelected = selectedIndices.has(frameIndex);
const frameDate = new Date(frame.timestamp);
const isInRange =
@@ -1499,8 +1499,7 @@ export const TimelineSlider = ({
frameDate <= selectionRange.end;
const hasAudio = frame?.devices?.some((d) => d.audio?.some((a) => a.transcription?.trim()));
- const isCurrent = frameIndex === currentIndex
- && frame.devices?.[0]?.device_id === frames[currentIndex]?.devices?.[0]?.device_id;
+ const isCurrent = frameIndex === currentIndex;
const matchesDevice = selectedDeviceId === "all" || frame.devices.some((d) => d.device_id === selectedDeviceId);
const matchesApp = selectedAppName === "all" || frame.devices.some((d) => d.metadata?.app_name === selectedAppName);
const matchesDomain = selectedDomain === "all" || frame.devices.some((d) => {