Skip to content

Commit ca9c416

Browse files
committed
fix(timeline): move getPlaybackTimeMs ref sync out of render phase
Per CodeRabbit review on #120: PlaybackCursor wrote to getPlaybackTimeMsRef.current directly in the render body instead of in an effect. Writing to a ref during render is a React anti-pattern — it can leave the ref holding a stale value from a discarded render pass under concurrent rendering. Moved the assignment into a useEffect keyed on getPlaybackTimeMs, matching the recommended pattern for "latest callback" refs. Verified: tsc --noEmit clean, biome clean, rafCoalescer.test.ts and zoomRegionUtils.test.ts pass (7/7).
1 parent 27695b9 commit ca9c416

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/components/video-editor/timeline/TimelineEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ function PlaybackCursor({
316316
// ancestor's (much heavier) re-render is in flight — see issue #111.
317317
const [liveTimeMs, setLiveTimeMs] = useState(currentTimeMs);
318318
const getPlaybackTimeMsRef = useRef(getPlaybackTimeMs);
319-
getPlaybackTimeMsRef.current = getPlaybackTimeMs;
319+
useEffect(() => {
320+
getPlaybackTimeMsRef.current = getPlaybackTimeMs;
321+
}, [getPlaybackTimeMs]);
320322

321323
useEffect(() => {
322324
if (!getPlaybackTimeMsRef.current) {

0 commit comments

Comments
 (0)