From 321f7ceb25e6ac4d6977a4ab330eea8bdcafe904 Mon Sep 17 00:00:00 2001 From: nmanu1 Date: Wed, 25 Oct 2023 10:55:46 -0400 Subject: [PATCH] Fix viewport selection bug --- .../studio-ui/src/components/IFramePortal.tsx | 51 ++----------------- .../components/Viewport/ViewportButton.tsx | 6 +-- .../src/components/Viewport/ViewportMenu.tsx | 14 +++-- .../src/components/Viewport/defaults.tsx | 14 ++--- .../tests/components/ViewportButton.test.tsx | 2 +- 5 files changed, 20 insertions(+), 67 deletions(-) diff --git a/packages/studio-ui/src/components/IFramePortal.tsx b/packages/studio-ui/src/components/IFramePortal.tsx index c05b56d65..668764f75 100644 --- a/packages/studio-ui/src/components/IFramePortal.tsx +++ b/packages/studio-ui/src/components/IFramePortal.tsx @@ -1,16 +1,7 @@ import { createPortal } from "react-dom"; -import { - Dispatch, - PropsWithChildren, - RefObject, - SetStateAction, - useEffect, - useRef, - useState, -} from "react"; +import { Dispatch, PropsWithChildren, SetStateAction, useEffect } from "react"; import useStudioStore from "../store/useStudioStore"; import { twMerge } from "tailwind-merge"; -import { Viewport } from "./Viewport/defaults"; export default function IFramePortal( props: PropsWithChildren<{ @@ -19,18 +10,13 @@ export default function IFramePortal( setIframeEl: Dispatch>; }> ) { - const previewRef = useRef(null); const iframeDocument = props.iframeEl?.contentWindow?.document; - const [viewport] = useStudioStore((store) => [store.pagePreview.viewport]); useParentDocumentStyles(iframeDocument); - const iframeCSS = twMerge( - "mr-auto ml-auto", - viewport.css, - useCSS(viewport, previewRef) - ); + const viewportCss = useStudioStore((store) => store.pagePreview.viewport.css); + const iframeCSS = twMerge("mr-auto ml-auto", viewportCss); return ( -
+