gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

UI Shaking When Dragging Grid with Larger or Equal Height into Another Grid

Open rolandsoh96 opened this issue 3 years ago • 2 comments

Description: I am encountering a UI issue with Gridstack when dragging a grid into another grid. If the height of the dragged grid is greater than or equal to the height of the dropped grid, the UI begins to shake uncontrollably when the dragged grid is close to the dropped grid.

Steps to Reproduce:

  1. Create two grids, one with a height greater than or equal to the other (e.g., draggedGridHeight >= droppedGridHeight).
  2. Initiate a drag operation on the larger grid.
  3. Drag it close to the smaller grid.
  4. Observe the rapid shaking of the UI.

Expected Behavior: The grids should align smoothly without any shaking, regardless of their relative heights.

Actual Behavior: The UI shakes uncontrollably when the dragged grid is close to the dropped grid.

Nested Grid Shaking.webm

rolandsoh96 avatar Aug 11 '23 02:08 rolandsoh96

oh that's gonna be fun to debug....

adumesny avatar Aug 11 '23 16:08 adumesny

not seeing this issue with latest code. closing.

AI code, but not needed /** ms to sit on a 'leave to empty space' before acting on it, so a leave+re-enter pair caused by

  • our own re-layout (rather than by the user moving) cancels out instead of shaking - see #2407 */ const leaveGrace = 30;

/** @internal a leave we haven't acted on yet. Taking an item into a grid resizes that grid (and

  • removing it from the source shrinks THAT one), which shifts the layout out from under a
  • stationary cursor and fires a leave - we then put everything back, it shifts again, we get an
  • enter... every frame, which is the "UI shaking" in #2407. Sitting on the leave for a beat lets
  • an immediate re-enter cancel it, so self-inflicted churn settles instead of oscillating. */ protected _leaveTimeout?: number;

protected _mouseEnter(e: MouseEvent): void { // console.log(${count++} Enter ${this.el.id}); // TEST this._cancelPendingLeave(); // back over us already - whatever moved under the cursor, stay put ... protected _mouseLeave(e: MouseEvent, calledByEnter = false): void { // console.log(${count++} Leave ${this.el.id}); // TEST if (!DDManager.dragElement || DDManager.dropElement !== this) return; e.preventDefault(); e.stopPropagation(); // Entering another grid already leaves us synchronously (see _mouseEnter), so only leaving to // empty space waits - and that's exactly the case our own re-layout keeps faking (#2407). if (!calledByEnter) { this._cancelPendingLeave(); const ev = Utils.initEvent(e, { target: e.target as HTMLElement, type: e.type }); this._leaveTimeout = window.setTimeout(() => { delete this._leaveTimeout; this._doMouseLeave(ev, false); }, leaveGrace); return; } this._doMouseLeave(e, calledByEnter); }

/** @internal drop a leave we scheduled but haven't acted on */ protected _cancelPendingLeave(): void { if (this._leaveTimeout) { window.clearTimeout(this._leaveTimeout); delete this._leaveTimeout; } }

/** @internal the actual leave work, once we're sure the cursor really did go away */ protected _doMouseLeave(e: MouseEvent, calledByEnter: boolean): void { if (!DDManager.dragElement || DDManager.dropElement !== this) return;

adumesny avatar Sep 28 '26 20:09 adumesny