I need to thoroughly understand the timeline positioning system in this codebase. The goal is to find redundancies, dead code, circular dependencies, or fragile patterns in how frame positions flow through the timeline.
Key files to explore:
src/tools/travel-between-images/components/Timeline/TimelineContainer/TimelineContainer.tsx - the main container, read fully
src/tools/travel-between-images/components/Timeline/hooks/useTimelineOrchestrator.ts - the orchestrator hook, read fully
Where framePositions originates and how it transforms into currentPositions
How fullMin, fullMax, fullRange are computed and what inputs they depend on
How imagePositions (the TRAILING_ENDPOINT_KEY-filtered version) is used
How drag state affects positions
How the trailing endpoint position integrates with the main position map
Any position-related memos that could be stale, redundant, or have unnecessary dependencies
Also look for:
localShotGenPositions - what is it and how does it relate to currentPositions?
pairInfo / pairDataByIndex - how are these derived from positions?
The imagePositionsWithPending augmentation in TimelineContainer
Give me a detailed report of the full data flow, and flag anything that looks redundant, fragile, or could be simplified. Be specific with line numbers and variable names.
Assistant
I'll conduct a thorough investigation of the timeline positioning system. Let me start by reading the key files.
Assistant
Now let me read the additional hooks to understand the full flow:
Assistant
Now let me check the endpoint drag hook:
Assistant
Perfect! Now I have all the key files. Let me search for any other related files that might be important for understanding the full picture:
Assistant
Let me check a few more of these to understand the full dependency graph:
Assistant
Let me check for any remaining critical hooks and understand the complete flow:
Assistant
User
I need precise line-by-line details for planning a refactor. Read each of these files in full and report back with exact contents, line numbers, and any cross-references I need to know about:
/Users/user_c042661f/Documents/reigh/src/tools/travel-between-images/components/Timeline/hooks/useComputedTimelineData.ts — full file
/Users/user_c042661f/Documents/reigh/src/tools/travel-between-images/components/Timeline/hooks/useTimelineDrag.ts — focus on calculateFinalPosition (lines ~135-137), currentDragFrame computation (line ~434-436), and how dynamicPositions is exported/used
The shotId parameter in useComputedTimelineData — confirm it is truly unused (voided), and check if it was ever used in the file
The forceUpdate pattern in useTimelineOrchestrator.ts (lines ~339-343) — read those lines and the surrounding 10 lines for context on WHY it might be there
How pairInfoWithPending flows in TimelineContainer.tsx — specifically lines 271-292 and what uses vs what uses (search for both identifiers in the file)
Assistant
I'll read all the files in parallel to gather the exact details you need.
Assistant
Now I have everything needed. Let me also quickly read the TimelineContainer.tsx lines 271–292, and the two specific test files, in parallel.
Assistant
Good. Now let me also get the broader context around pairInfoWithPending usage in the same file, and the area just above line 271 for full context.
Assistant
Now let me read the lines around 175-195 for the pairInfo destructure context, and lines around 395-410 and 540-555 for the two usages of pairInfoWithPending.
Assistant
Now let me create a comprehensive analysis document with all my findings:
Detailed Report: Timeline Positioning System Data Flow Analysis
Based on my thorough examination of the timeline positioning system, here's a comprehensive analysis of redundancies, fragility, and optimization opportunities:
1. FRAMEPOSITIONS ORIGINATION AND TRANSFORMATION FLOW
Line 132-141: anyImageHasVideo from parentSegmentSlots
Line 229-242: liveTrailingSlot from currentPositions (post-orchestrator)
Split design justified (lines 98-107) for "proactive reservation"
Passed to orchestrator:
Line 223: hasExistingTrailingVideo: hasCallbackTrailingVideo || anyImageHasVideo
Used in trailingEffectiveEnd calculation (line 216)
After orchestrator:
liveTrailingVideoUrl recomputed from live positions (line 229-242)
Used by useTrailingEndpoint but NOT fed back into dimensions
Fragility: The hasExistingTrailingVideo flag is computed BEFORE orchestrator sees dynamic positions. If user drags images and changes which one is last, the orchestrator's fullMax was calculated with stale trailing video assumptions. The live slot detection happens POST-orchestrator (line 229-242) but doesn't re-expand fullMax if a new trailing video is detected mid-drag.
Frozen Dimensions During Drag:
Lines 268-291 (useTimelineOrchestrator)
Stores dragStartDimensionsRef on drag start
Used to prevent fullMax shrinking during image moves
Create a shared utility hook: useImageOnlyPositions(currentPositions)
Used by both useComputedTimelineData and useTrailingEndpoint
Unify pair data sources:
Compute pairDataByIndex with frame data baked in
Export pairInfo as derived from pairDataByIndex (transform map to array)
Single source of truth for pairs
Investigate localShotGenPositions:
Search SegmentOutputStrip and related components for actual usage
If truly unused, remove from useComputedTimelineData
If used, document its purpose clearly
Fix pairInfoWithPending dependencies:
Remove pairInfo from dependency array
Or eliminate entirely if can be computed in TimelineContainer directly
Memoize pairInfo in useComputedTimelineData:
Wrap line 32 with useMemo to prevent cascading invalidations
Document trailing endpoint quantization:
Add comment explaining why trailing endpoint is preserved (not quantized)
Clarify the pre/post-orchestrator split reasoning
Add explicit window-resize-during-drag guard:
Either freeze containerWidth like dimensions OR
Invalidate drag if container resizes while dragging
CONCLUSION
The timeline positioning system has 3 major redundancies (imageOnlyPositions, pairInfo duplication, pairDataByIndex + pairInfo split) and 5 fragility points (pre-orchestrator trailing detection, quantization preview skipping, containerWidth changes, endpoint push mode timing, dimension freezing edge cases). The core flow is sound but would benefit from unified pair data sources and elimination of computed-but-duplicated filters.
pairInfoWithPending
pairInfo
In useComputedTimelineData.ts, confirm getPairInfo is called bare (no useMemo) at line 32
Check if there are any tests for useComputedTimelineData or useTimelineDrag:
This is a no-op passthrough — it takes targetFrame and returns it unchanged, with an empty dependency array. It exists as a named abstraction point (presumably once held quantization/snapping logic that was removed, or is a placeholder for future logic).
This is computed inline during render (not inside a useCallback or useMemo). It calls calculateFinalPosition(calculateTargetFrame(...)). Since calculateFinalPosition is a no-op, this reduces to: calculateTargetFrame(dragState.currentX, containerRect).
dynamicPositions export:
ts
L450 dynamicPositions: calculateDragPreview,
dynamicPositions is exported as a function reference (calculateDragPreview), not a computed value. It is a useCallback (lines 248–253) that calls calculateDragPositions(currentMousePosRef.current.x, true).
At the call site in useTimelineOrchestrator.ts line 563:
ts
L563 const currentPositions = dynamicPositions();
It is called as a function on every render of the orchestrator. This means it invokes calculateDragPositions on every render cycle, not lazily. The result currentPositions is then passed straight into useComputedTimelineData and into the return object.
dynamicPositions (the function reference itself) is also passed to useEndpointDrag at line 554.
3. shotId in useComputedTimelineData — Confirmed Unused
Lines 10, 26–27, 31:
ts
L10 shotId: string; // in the Props interface
L26 shotId: _shotId, // destructured with rename to _shotId
L31 void _shotId; // explicitly suppressed with void operator
_shotId is referenced only at line 31 (void _shotId) to silence a TypeScript/ESLint "unused variable" warning. It is never read for any computation in the file. There are no other references to shotId or _shotId anywhere in the file body.
The prop exists in the interface and is passed in at the orchestrator call site (useTimelineOrchestrator.ts lines 569–576):
Why it's there: The comment on L337 says "Force re-render when zoom changes." The mechanism is a deferred setState({}) via a setTimeout(..., 0) — this triggers a React re-render on the next tick after zoomLevel changes.
The reason this likely exists: containerWidth on line 239 is read synchronously from containerRef.current?.clientWidth || 1000. After a zoom changes the DOM layout, the clientWidth won't reflect the new layout until the browser has painted. The setTimeout(0) defers the re-render until after the layout flush, so that the orchestrator picks up the updated containerWidth (and containerRect) for the new zoom state. Without it, the first render after a zoom would compute positions against stale container dimensions.
5. pairInfoWithPending vs pairInfo in TimelineContainer.tsx
Where pairInfo comes from:
ts
L181 pairInfo, // destructured from useTimelineOrchestrator() return
This augments pairInfo to include a "phantom" pending pair when a drop/duplicate is in flight. imagePositionsWithPending is the positions map with PENDING_POSITION_KEY injected (lines 262–269).
pairInfoWithPending usages:
Line 401: Passed to SegmentOutputStrip as pairInfo prop:
This is a bare function call at the top level of the hook body — no useMemo, no useCallback. It runs on every render of useComputedTimelineData. Since useComputedTimelineData is called from useTimelineOrchestrator which itself re-renders on every drag frame (because dynamicPositions() is called inline), getPairInfo is invoked on every animation frame during drag.
7. Tests for useComputedTimelineData and useTimelineDrag
Both test files exist and are smoke tests only — they confirm the export is defined and callable. No behavioral tests.
calculateFinalPosition is dead logic — L135–137 is a passthrough. currentDragFrame (L434–436) could inline calculateTargetFrame(...) directly; the calculateFinalPosition indirection adds no value and appears in the useCallback dep array of calculateDragPositions (L241), adding a stable-but-unnecessary entry.
dynamicPositions is a function, not a value — it must be called (dynamicPositions()) at the consumption site. It is called every render at useTimelineOrchestrator.ts:563. This means drag position recomputation is not lazily deferred; it runs unconditionally on every render.
getPairInfo at L32 runs bare on every render — it is the only computation in the hook not wrapped in useMemo. Given that pairInfo flows into the return and is passed downstream to usePairSettingsHandler and up through pairInfoWithPending into render, this is a potential memoization gap during drag.
shotId can be safely removed from useComputedTimelineData's interface and call site — it is fully inert. The prop was likely a remnant from before the hook was extracted.
pairInfo vs pairInfoWithPending split is intentional — usePairSettingsHandler deliberately gets the real pairInfo (no ghost pairs); only the visual rendering layer (SegmentOutputStrip and the pair region map) gets the pending-augmented version.
Both test files are structural stubs — any refactor can safely change the hook signatures; there are no behavioral tests to update or protect.