Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

update on resize

Oleg Isonenda49086eb2bf
diff --git a/app/canvas/shared/use-outline.tsx b/app/canvas/shared/use-outline.tsx
index c3ff48de47..61409f2480 100644
--- a/app/canvas/shared/use-outline.tsx
+++ b/app/canvas/shared/use-outline.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useMemo, useState } from "react";
+import { useCallback, useEffect, useMemo, useState } from "react";
import { createPortal } from "react-dom";
import { type Instance } from "@webstudio-is/sdk";
import { getBoundingClientRect } from "~/shared/dom-utils";
@@ -30,12 +30,20 @@ const useStyle = (element?: HTMLElement) => {
// style on the page changes because we have no idea how any layout changes
// can impact the position or size of the outline.
const handleUpdate = useCallback(() => {
+ if (element === undefined) return;
getBoundingClientRect.cache.delete(element);
forceRender(!rerenderFlag);
}, [element, rerenderFlag]);
useOnRender(handleUpdate);
+ useEffect(() => {
+ window.addEventListener("resize", handleUpdate);
+ return () => {
+ window.removeEventListener("resize", handleUpdate);
+ };
+ }, [handleUpdate]);
+
return useMemo(
() => {
if (element === undefined) return;