From 2a8a8635dec156227a5e86a68e370ee87c7c67aa Mon Sep 17 00:00:00 2001 From: Roman Pominov Date: Sat, 23 Jul 2022 14:26:15 +0300 Subject: [PATCH] create probe lazily because of SSR --- .../components/primitives/dnd/placement.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/designer/app/shared/design-system/components/primitives/dnd/placement.tsx b/apps/designer/app/shared/design-system/components/primitives/dnd/placement.tsx index a20a29d724..9dac65f42d 100644 --- a/apps/designer/app/shared/design-system/components/primitives/dnd/placement.tsx +++ b/apps/designer/app/shared/design-system/components/primitives/dnd/placement.tsx @@ -4,7 +4,13 @@ import { Box } from "../../box"; export type Rect = Pick; type Point = { x: number; y: number }; -const probe = document.createElement("div"); +let probeCache: undefined | HTMLElement; +const getProbe = () => { + if (probeCache === undefined) { + probeCache = document.createElement("div"); + } + return probeCache; +}; /** * We place a div at the position where future drop will happen. @@ -17,6 +23,7 @@ const getPlacement = ({ target: HTMLElement; index?: number; }) => { + const probe = getProbe(); const { children } = target; if (index > children.length - 1) { target.appendChild(probe);