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.

fix reparenting infinite loop with spec

Oleg Isonen2ddf5a747cd5
diff --git a/app/canvas/canvas.tsx b/app/canvas/canvas.tsx
index 1a7c8278a9..905d1c6762 100644
--- a/app/canvas/canvas.tsx
+++ b/app/canvas/canvas.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useMemo, useState } from "react";
+import { useMemo, useState } from "react";
import { DndProvider } from "react-dnd";
import { TouchBackend } from "react-dnd-touch-backend";
import {
diff --git a/app/canvas/hooks/tree.ts b/app/canvas/hooks/tree.ts
index d3e7058707..c728d946c3 100644
--- a/app/canvas/hooks/tree.ts
+++ b/app/canvas/hooks/tree.ts
@@ -63,8 +63,17 @@ export const useReparentInstance = ({
rootInstance: Instance;
setRootInstance: (instance: Instance) => void;
}) => {
+ // Used to avoid reparenting in infinite loop when spec didn't change
+ const usedSpec = useRef<InstanceReparentingSpec>();
+
useEffect(() => {
- if (instanceReparentingSpec === undefined) return;
+ if (
+ instanceReparentingSpec === undefined ||
+ usedSpec.current === instanceReparentingSpec
+ ) {
+ return;
+ }
+ usedSpec.current = instanceReparentingSpec;
const updatedRootInstance = reparentInstance(
rootInstance,
instanceReparentingSpec