Use useEffectEvent for effects with deliberately narrow deps (#11550)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tomasz Zawadzki
2026-09-07 12:18:08 +02:00
committed by GitHub
parent 8e52eba582
commit 52345ad3ca
5 changed files with 48 additions and 19 deletions
@@ -1,4 +1,11 @@
import {useCallback, useEffect, useId, useRef, useState} from 'react'
import {
useCallback,
useEffect,
useEffectEvent,
useId,
useRef,
useState,
} from 'react'
import {View} from 'react-native'
import {useLingui} from '@lingui/react/macro'
import type * as HlsTypes from 'hls.js'
@@ -274,6 +281,14 @@ function useHLS({
},
)
/*
* The hls handler below must call the latest `updateCuePositions` without the
* effect tearing down and re-attaching every time its identity changes.
*/
const onSubtitleFragProcessed = useEffectEvent(() => {
updateCuePositions()
})
useEffect(() => {
if (!videoRef.current) return
if (!Hls) return
@@ -312,7 +327,7 @@ function useHLS({
})
hls.on(Hls.Events.SUBTITLE_FRAG_PROCESSED, () => {
updateCuePositions()
onSubtitleFragProcessed()
})
hls.on(Hls.Events.FRAG_BUFFERED, (_event, {frag}) => {