lloydzhou 1 ano atrás
pai
commit
556d563ba0
2 arquivos alterados com 13 adições e 5 exclusões
  1. 7 3
      app/components/artifact.tsx
  2. 6 2
      app/components/ui-lib.tsx

+ 7 - 3
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;

+ 6 - 2
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 (
     <div ref={ref} style={{ position: "relative" }} {...rest}>