From 9bf20501110d5d106fcd8a50695f7886382233c5 Mon Sep 17 00:00:00 2001 From: Merlin Scheurer Date: Sat, 23 May 2026 11:02:49 +0200 Subject: [PATCH] Fix do not rely on useEffect to set google cast function before script load --- frontend/src/components/GoogleCast.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/GoogleCast.tsx b/frontend/src/components/GoogleCast.tsx index d862d343..e7eb36cd 100644 --- a/frontend/src/components/GoogleCast.tsx +++ b/frontend/src/components/GoogleCast.tsx @@ -138,6 +138,13 @@ const GoogleCast = ({ video, setRefresh, onWatchStateChanged }: GoogleCastProps) // eslint-disable-next-line react-hooks/exhaustive-deps }, [setRefresh, video]); + // @ts-expect-error __onGCastApiAvailable is the google cast window hook ( source: https://developers.google.com/cast/docs/web_sender/integrate ) + window['__onGCastApiAvailable'] ??= function (isAvailable: boolean) { + if (isAvailable) { + setup(); + } + }; + const startPlayback = useCallback(() => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const chrome = (globalThis as any).chrome; @@ -195,15 +202,6 @@ const GoogleCast = ({ video, setRefresh, onWatchStateChanged }: GoogleCastProps) // eslint-disable-next-line react-hooks/exhaustive-deps }, [video?.media_url, video?.subtitles, video?.title, video?.vid_thumb_url]); - useEffect(() => { - // @ts-expect-error __onGCastApiAvailable is the google cast window hook ( source: https://developers.google.com/cast/docs/web_sender/integrate ) - window['__onGCastApiAvailable'] = function (isAvailable: boolean) { - if (isAvailable) { - setup(); - } - }; - }, [setup]); - useEffect(() => { console.log('isConnected', isConnected); if (isConnected) {