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 getValidChildren

Roman Pominovbfc9813a78df
diff --git a/apps/designer/app/canvas/shared/use-drag-drop.ts b/apps/designer/app/canvas/shared/use-drag-drop.ts
index 17094b6555..3cd73d34e7 100644
--- a/apps/designer/app/canvas/shared/use-drag-drop.ts
+++ b/apps/designer/app/canvas/shared/use-drag-drop.ts
@@ -7,6 +7,7 @@ import { getInstancePath, createInstance } from "~/shared/tree-utils";
import {
findInstanceByElement,
getInstanceElementById,
+ getInstanceIdFromElement,
} from "~/shared/dom-utils";
import {
type DropTarget,
@@ -138,15 +139,9 @@ export const useDragAndDrop = () => {
},
getValidChildren: (parent) => {
- if (!(parent instanceof HTMLBodyElement)) {
- return parent.children;
- }
- return Array.from(parent.children).filter((child) => {
- return (
- !(child instanceof HTMLScriptElement) &&
- !(child instanceof HTMLLinkElement)
- );
- });
+ return Array.from(parent.children).filter(
+ (child) => getInstanceIdFromElement(child) !== undefined
+ );
},
});
diff --git a/packages/design-system/src/components/primitives/dnd/use-drop.ts b/packages/design-system/src/components/primitives/dnd/use-drop.ts
index 3c52bc500f..d3fd63a736 100644
--- a/packages/design-system/src/components/primitives/dnd/use-drop.ts
+++ b/packages/design-system/src/components/primitives/dnd/use-drop.ts
@@ -81,15 +81,13 @@ export const useDrop = <Data>(props: UseDropProps<Data>): UseDropHandlers => {
// We want to return a stable object to avoid re-renders when it's a dependency
return useMemo(() => {
const getChildrenRectsMemoized = (parent: Element) => {
+ const { getValidChildren = (parent) => parent.children } =
+ latestProps.current;
const fromCache = state.current.childrenRectsCache.get(parent);
if (fromCache !== undefined) {
return fromCache;
}
- const children =
- latestProps.current.getValidChildren !== undefined
- ? latestProps.current.getValidChildren(parent)
- : parent.children;
- const result = getChildrenRects(parent, children);
+ const result = getChildrenRects(parent, getValidChildren(parent));
state.current.childrenRectsCache.set(parent, result);
return result;
};