Skip to content

Commit 9b9e1b0

Browse files
authored
Merge pull request Expensify#88314 from TaduJR/fix-video-player-render-loop
2 parents d18281d + fc11b0e commit 9b9e1b0

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/components/VideoPlayer/BaseVideoPlayer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ function BaseVideoPlayer({
8383
useVideoPlayer(sourceURL, (player) => {
8484
player.loop = isLooping;
8585
player.muted = true;
86-
player.timeUpdateEventInterval = 0.1;
86+
player.timeUpdateEventInterval = 0;
8787
}),
8888
);
8989
/* eslint-enable no-param-reassign */
9090

91-
const isPlaying = videoPlayerRef.current.playing;
91+
// `useEvent` — direct `.playing` read wouldn't re-render when play state changes.
92+
const {isPlaying} = useEvent(videoPlayerRef.current, 'playingChange', {isPlaying: videoPlayerRef.current.playing, oldIsPlaying: false} as PlayingChangeEventPayload);
93+
9294
const {currentTime, bufferedPosition} = useEvent(videoPlayerRef.current, 'timeUpdate', {currentTime: 0, bufferedPosition: 0} as TimeUpdateEventPayload);
9395
const {status} = useEvent(videoPlayerRef.current, 'statusChange', {status: shouldUseSharedVideoElement ? playerStatus.current : 'loading'} as StatusChangeEventPayload);
9496

@@ -285,6 +287,8 @@ function BaseVideoPlayer({
285287

286288
useEventListener(videoPlayerRef.current, 'playingChange', (payload: PlayingChangeEventPayload) => {
287289
const isVideoPlaying = payload.isPlaying;
290+
// Toggled in the listener (not a `useEffect`) — the web setter synchronously emits `timeUpdate`, which would re-enter `useEvent` from render.
291+
videoPlayerRef.current.timeUpdateEventInterval = isVideoPlaying ? 0.1 : 0;
288292
if (isVideoPlaying && isEnded) {
289293
setIsEnded(false);
290294
}

src/components/VideoPlayer/index.native.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React from 'react';
1+
import React, {useState} from 'react';
22
import uniqueIDForVideoWithoutReport from '@components/VideoPlayerContexts/PlaybackContext/uniqueID';
33
import CONST from '@src/CONST';
44
import BaseVideoPlayer from './BaseVideoPlayer';
55
import type VideoPlayerProps from './types';
66

77
function VideoPlayer({videoControlsStyle, shouldUseControlsBottomMargin = true, ...props}: VideoPlayerProps) {
8-
const {fakeReportID} = uniqueIDForVideoWithoutReport();
8+
// `fakeReportID` is a getter that increments each access — freeze it per instance.
9+
const [fakeReportID] = useState(() => uniqueIDForVideoWithoutReport().fakeReportID);
910
const {reportID} = props;
1011

1112
return (

src/components/VideoPlayer/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React from 'react';
1+
import React, {useState} from 'react';
22
import uniqueIDForVideoWithoutReport from '@components/VideoPlayerContexts/PlaybackContext/uniqueID';
33
import BaseVideoPlayer from './BaseVideoPlayer';
44
import type VideoPlayerProps from './types';
55

66
function VideoPlayer(props: VideoPlayerProps) {
7-
const {fakeReportID} = uniqueIDForVideoWithoutReport();
7+
// `fakeReportID` is a getter that increments each access — freeze it per instance.
8+
const [fakeReportID] = useState(() => uniqueIDForVideoWithoutReport().fakeReportID);
89
const {reportID} = props;
910

1011
return (

0 commit comments

Comments
 (0)