fix(event): fix stale callbacks

This commit is contained in:
2026-07-16 13:58:32 +02:00
parent 645b226359
commit 0d8b33aee3
+2 -4
View File
@@ -108,18 +108,16 @@ export const useEvent = <Event extends keyof OmniEvents>(
prevRef.current = value; prevRef.current = value;
}, [value, config]); }, [value, config]);
// prev/next are triggered by the app (or the media session) rather than the
// media element
useEffect(() => { useEffect(() => {
// don't use callbackRef.current directly to keep future callback updates
const cb = () => (callbackRef.current as () => void)();
if (event === "prev") { if (event === "prev") {
const cb = callbackRef.current as () => void;
player.onPrev.add(cb); player.onPrev.add(cb);
return () => { return () => {
player.onPrev.delete(cb); player.onPrev.delete(cb);
}; };
} }
if (event === "next") { if (event === "next") {
const cb = callbackRef.current as () => void;
player.onNext.add(cb); player.onNext.add(cb);
return () => { return () => {
player.onNext.delete(cb); player.onNext.delete(cb);