Execute the approved plan in the repository. Project directory:…
- User
Execute the approved plan in the repository.
codeProject directory: /Users/user_c042661f/Documents/announcement-video Idea:Timeline & drag performance optimization: Fix lag when many clips are on the timeline (e.g., 63 image clips). The lag comes from: (1) ClipAction thumbnails — every clip creates an img or video element with no lazy loading, (2) Remotion Player mounts ALL clips as Sequence components even when not visible at current frame, (3) getActionRender callback in TimelineEditor creates new React elements on every render — not memoized per clip, (4) The resize divider drag between preview and timeline can lose pointer events. Also re-apply the thumbnail feature (which was reverted) in a performant way. Must not break existing functionality — drag-and-drop, cross-track drag, clip editing, preview playback all must keep working.
User notes and answers:
-
Answers to questions: (1) Build thumbnails fresh using registry data - no prior implementation exists. (2) Image-only thumbnails are fine; colored blocks for video clips. (3) 1-second buffer for Remotion lazy mounting is acceptable.
codeExecution tracking source of truth (`finalize.json`): {"tasks": [ { "id": "T1", "description": "Split TimelineContext into two contexts: TimelineEditorContext (data, selectedClipId, selectedTrackId, editing callbacks, track management, preferences, compositionSize, trackScaleMap) and TimelinePlaybackContext (currentTime, formatTime, previewRef, playerContainerRef, timelineRef, timelineWrapperRef, onPreviewTimeUpdate, onCursorDrag, onClickTimeArea). In useTimelineState.ts, split the single returned object into two memoized values. In TimelineContext.tsx (or a new pair of files), create two React contexts and a combined provider. Export useEditorContext() and usePlaybackContext() hooks. CRITICAL per flag context-consumer-split-misread: PreviewPanel uses BOTH contexts (it reads data, resolvedConfig, selectedClipId, setSelectedClipId, onOverlayChange from editor AND previewRef, playerContainerRef, currentTime, onPreviewTimeUpdate from playback). PropertiesPanel also uses BOTH (it reads currentTime from playback for the playheadSeconds prop to ClipPanel, plus all editor state). Components that use both simply call both hooks. Memoize each context value object with useMemo keyed on its constituent fields so reference identity is stable when fields haven't changed. Update ALL consumers: TimelineEditor (editor only), PreviewPanel (both), PropertiesPanel (both), VideoEditorPage (both), RemotionPreview (check actual imports).", "depends_on": [], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T2", "description": "Memoize ClipAction with React.memo and stabilize its callback props. In ClipAction.tsx, wrap the component export in React.memo() with a custom areEqual comparator that compares: action.id, action.start, action.end, clipMeta fields by value (asset, track, from, to, speed, hold, volume, entrance, exit, transition, effects), isSelected, and thumbnailSrc. Refactor props: replace per-clip closures onSelect/onDelete with stable callbacks that accept clipId/trackId parameters \u2014 onSelect(clipId, trackId) and onDelete(clipId). ClipAction calls these with its own IDs internally.", "depends_on": [ "T1" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T3", "description": "Memoize getActionRender in TimelineEditor.tsx. Extract the inline getActionRender function (currently ~line 130) into a useCallback. Define stable handleClipSelect and handleClipDelete callbacks with useCallback that call setSelectedClipId/setSelectedTrackId and handleDeleteClip respectively. Pass these stable refs through getActionRender to ClipAction. Dependencies for getActionRender useCallback: data.meta, data.assetMap, data.registry, selectedClipId, handleClipSelect, handleClipDelete, plus thumbnailMap from T4.", "depends_on": [ "T1", "T2" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T4", "description": "Add lazy-loaded image thumbnails to ClipAction. In TimelineEditor.tsx, build a thumbnailMap: Record<string, string> via useMemo \u2014 iterate data.resolvedConfig.clips, and for each image clip (where assetEntry.type?.startsWith('image')), map clip.id \u2192 assetEntry.src. Pass thumbnailMap[action.id] as thumbnailSrc prop to ClipAction. In ClipAction.tsx, when thumbnailSrc is present, render: <img src={thumbnailSrc} loading="lazy" decoding="async" draggable={false} className="pointer-events-none absolute inset-0 h-full w-full object-cover" onError={(e) => { (e.target as HTMLImageElement).style.display = 'none'; }} /> plus a gradient overlay div with pointer-events-none. Skip thumbnails for uploading clips (id starts with 'uploading-') and text clips (clipType === 'text'). CRITICAL: draggable={false} and pointer-events-none are mandatory to not break drag interactions.", "depends_on": [ "T2", "T3" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T5", "description": "Optimize Remotion Player with lazy clip mounting by frame proximity. CRITICAL per flag lazy-sequence-placement: The lives INSIDE VisualClipSequence (VisualClip.tsx:126-130), NOT in TimelineRenderer. The lazy guard must go INSIDE VisualClipSequence, before the heavy VisualClip/VisualAsset render, NOT as an outer wrapper. Implementation: In VisualClipSequence (VisualClip.tsx:119-131), add a LazyGuard component rendered inside the existing . LazyGuard uses useCurrentFrame() and useVideoConfig() to check if the current frame is within BUFFER_FRAMES (30 frames \u2248 1s) of the clip's range. If outside the buffer, return null (the Sequence stays mounted maintaining timing, but the heavy Img/Video/effects are not rendered). The [...visualTracks].reverse() ordering in TimelineRenderer.tsx:83 is untouched. TextClipSequence is excluded from lazy mounting (text is lightweight).", "depends_on": [], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T6", "description": "Fix resize divider pointer event stealing in VideoEditorPage.tsx. In the onDividerMouseDown handler (~line 54-88), when the drag starts, add pointer-events-none class to playerContainerRef.current. Remove it in the mouseup cleanup. playerContainerRef is already available from useTimelineContext (useTimelineState.ts:144). If not currently destructured in VideoEditorPage, add it to the destructuring.", "depends_on": [], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T7", "description": "Full regression test: verify all existing interactions work with all optimizations applied. Test checklist: (1) asset drag-drop from panel to timeline, (2) cross-track drag of clips, (3) within-track drag/reorder, (4) clip resize handles, (5) clip selection and deselection, (6) clip editing in PropertiesPanel, (7) clip delete, (8) preview playback and scrubbing, (9) keyboard shortcuts, (10) resize divider drag, (11) image thumbnails display on image clips, (12) video clips show colored blocks (no thumbnails). Run the dev server and manually verify.", "depends_on": [ "T1", "T2", "T3", "T4", "T5", "T6" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" } ], "watch_items": [ "Context split (T1): PreviewPanel and PropertiesPanel both consume BOTH editor and playback contexts \u2014 do not assign them to only one. PreviewPanel reads data/resolvedConfig/selectedClipId/setSelectedClipId/onOverlayChange (editor) AND previewRef/playerContainerRef/currentTime/onPreviewTimeUpdate (playback). PropertiesPanel reads currentTime (playback) for ClipPanel's playheadSeconds prop.", "Lazy Sequence placement (T5): The wrapper lives INSIDE VisualClipSequence at VisualClip.tsx:126-130, not in TimelineRenderer. The lazy guard must render inside the Sequence (before VisualClip), not outside it. If you return null from outside the Sequence, the Sequence disappears and Remotion timing breaks.", "Thumbnail drag safety (T4): The element MUST have draggable={false} AND className including pointer-events-none. Without these, native browser image drag will steal the gesture from clip drag-and-drop and cross-track drag handlers in useCrossTrackDrag.ts.", "useMemo stability (T1): The whole point of splitting contexts is to stabilize object identity. Each context value must be wrapped in useMemo with correct dependency arrays. If you accidentally spread extra fields or omit useMemo, the optimization is nullified.", "getActionRender dependencies (T3): The @xzdarcy/react-timeline-editor library calls getActionRender for all visible actions on every render. The useCallback must have minimal, stable dependencies to avoid invalidation. Include thumbnailMap (from T4) in dependencies.", "Custom areEqual for React.memo (T2): ClipAction receives objects (clipMeta, action) that may have new references but same values. The default shallow comparison will fail. The custom comparator must do value comparison of the relevant fields.", "TextClipSequence exclusion (T5): TextClipSequence in TimelineRenderer.tsx:29 should NOT get the lazy guard \u2014 text rendering is lightweight and doesn't mount heavy media elements.", "Existing dirty state: The working tree has uncommitted changes in multiple files including TimelineEditor.tsx, useTimelineState.ts, PropertiesPanel.tsx, and TimelineRenderer.tsx. Read the current working-tree state of each file before editing \u2014 do not assume the git HEAD version is current." ], "sense_checks": [ { "id": "SC1", "task_id": "T1", "question": "Does TimelineEditor only subscribe to useEditorContext() (not usePlaybackContext()), and does it NOT re-render when currentTime changes during playback? Verify with React DevTools Profiler highlight-updates if possible.", "verdict": "" }, { "id": "SC2", "task_id": "T2", "question": "With 63 clips visible, does selecting a clip cause only 2 ClipAction re-renders (old selected + new selected), not 63? Does the custom areEqual comparator correctly prevent re-renders from new object references?", "verdict": "" }, { "id": "SC3", "task_id": "T3", "question": "Is the getActionRender useCallback reference stable across renders when no editing operations occur? Do the dependency arrays only include values that actually change on edit, not on every render?", "verdict": "" }, { "id": "SC4", "task_id": "T4", "question": "Do image clip thumbnails display correctly, and can you drag a thumbnail clip (both within-track and cross-track) without the browser's native image drag interfering? Does the onError fallback hide broken images gracefully?", "verdict": "" }, { "id": "SC5", "task_id": "T5", "question": "With the lazy guard in place, does scrubbing to various timeline positions show clips appearing smoothly (no pop-in at normal playback speed)? Are only ~1-5 Img/Video components mounted at any given frame, not 63? Does the Sequence still exist in the React tree even when its contents are null?", "verdict": "" }, { "id": "SC6", "task_id": "T6", "question": "Can you rapidly drag the preview/timeline resize divider without it sticking, jumping, or losing pointer tracking \u2014 even when dragging over the Remotion Player iframe area?", "verdict": "" }, { "id": "SC7", "task_id": "T7", "question": "Do all 12 regression items pass? Specifically: asset drag-drop, cross-track drag, within-track drag, clip resize, clip selection/editing, clip delete, preview playback, keyboard shortcuts, divider drag, thumbnails on images, colored blocks on videos, no console errors?", "verdict": "" } ], "meta_commentary": "Execution guidance:\n\n T1 (context split) is the foundation \u2014 it eliminates ~30fps re-renders that would undermine all other memoization work. T2+T3 are tightly coupled and must land together. T4 builds on T2+T3's memoization so thumbnails don't cause re-render storms. T5 and T6 are independent of each other and of T1-T4; they can be done in parallel with any step.\n\n\n1. The plan says PreviewPanel uses only playback context and PropertiesPanel uses only editor context. This is wrong. Both components use both contexts. PreviewPanel reads editor data (data, resolvedConfig, selectedClipId, setSelectedClipId, onOverlayChange) and playback state (previewRef, playerContainerRef, currentTime, onPreviewTimeUpdate). PropertiesPanel passes currentTime as playheadSeconds to ClipPanel. Both must import both hooks.\n\n2. The plan says to wrap VisualClipSequence with a LazyVisualClip in TimelineRenderer. This is wrong \u2014 the lives inside VisualClipSequence (VisualClip.tsx:126-130). Wrapping from outside and returning null would remove the Sequence entirely, breaking Remotion timing. Instead, add the frame-proximity guard INSIDE VisualClipSequence, between the Sequence and the VisualClip component. The Sequence stays mounted (preserving timing), but the heavy media elements (Img, Video, effects) are skipped when far from the current frame.\n\n Multiple target files have uncommitted changes. Always read the current file state before editing \u2014 the working tree may differ from git HEAD.\n\n The goal is <16ms frame times with 63 image clips. The context split (T1) is the biggest win. Memoization (T2+T3) is the second biggest. Thumbnails (T4) add visual value without perf cost if memoization is correct. Lazy Remotion mounting (T5) helps preview playback but not the timeline editor itself." }
-
- Assistant