diff --git a/app/components/artifact.tsx b/app/components/artifact.tsx index 9258157f6..0c3ee84a8 100644 --- a/app/components/artifact.tsx +++ b/app/components/artifact.tsx @@ -33,14 +33,18 @@ export function HTMLPreview(props: { */ useEffect(() => { - window.addEventListener("message", (e) => { + const handleMessage = (e) => { const { id, height, title } = e.data; setTitle(title); if (id == frameId.current) { setIframeHeight(height); } - }); - }, [iframeHeight]); + }; + window.addEventListener("message", handleMessage); + return () => { + window.removeEventListener("message", handleMessage); + }; + }, []); const height = useMemo(() => { const parentHeight = props.height || 600; diff --git a/app/components/ui-lib.tsx b/app/components/ui-lib.tsx index a23be8251..aff524b12 100644 --- a/app/components/ui-lib.tsx +++ b/app/components/ui-lib.tsx @@ -528,11 +528,15 @@ export function FullScreen(props: any) { } }, []); useEffect(() => { - document.addEventListener("fullscreenchange", (e) => { + const handleScreenChange = (e) => { if (e.target === ref.current) { setFullScreen(!!document.fullscreenElement); } - }); + }; + document.addEventListener("fullscreenchange", handleScreenChange); + return () => { + document.removeEventListener("fullscreenchange", handleScreenChange); + }; }, []); return (