diff --git a/app/client/src/utils/boxHelpers.ts b/app/client/src/utils/boxHelpers.ts index 5ade38372de3..1c6af664c317 100644 --- a/app/client/src/utils/boxHelpers.ts +++ b/app/client/src/utils/boxHelpers.ts @@ -6,10 +6,21 @@ export interface Rect { } export const areIntersecting = (r1: Rect, r2: Rect) => { - return !( - r2.left >= r1.right || - r2.right <= r1.left || - r2.top >= r1.bottom || - r2.bottom <= r1.top - ); + // Check left/right overlap first, with short-circuits to avoid unnecessary property reads. + const l2 = r2.left; + const r1r = r1.right; + if (!(l2 < r1r)) return false; + + const r2r = r2.right; + const l1 = r1.left; + if (!(r2r > l1)) return false; + + // Check top/bottom overlap next. + const t2 = r2.top; + const b1 = r1.bottom; + if (!(t2 < b1)) return false; + + const b2 = r2.bottom; + const t1 = r1.top; + return b2 > t1; };