Skip to content

item not moved (to alt position) when colliding fails with an object #2819

Closed

Description

@Hickays

Subject of the issue

When dragging, if the mouse position shifts downward by a certain distance after being pressed, a lagging effect occurs, making it look less "smooth." Attached is a video.

Your environment

  • version of gridstack.js 10.3.1
  • Windows 11 / Chrome 129

Steps to reproduce

in the demo environment https://jsfiddle.net/adumesny/jqhkry7g

20241015_145017.mp4

Expected behavior

The first time when dragging, the mouse remains steady, and everything displays normally.
From the second time onward, start dragging with the mouse on the upper part of the element, then shift downward by a certain distance, and the result is not as smooth.
On the contrary, when starting to drag with the mouse on the lower part of the element and shifting upward during the drag, the process remains smooth.

Activity

  1. adumesny commented on Oct 15, 2024

    @adumesny
    Member

    pretty sure this is a dup of another bug. nothing to do with mouse lag. It's trying to collide with item below and failing to use alternative item to move when the first item fails to collide.

    Also would have been helpful to modify the example to default to that layout issue, so I don't have to.

  2. changed the title [-]When dragging, a slight mouse offset causes a "lagging" effect.[/-] [+]item not moved when colliding fails with another object[/+] on Oct 15, 2024
  3. changed the title [-]item not moved when colliding fails with another object[/-] [+]item not moved (to alt space) when colliding fails with another object[/+] on Oct 15, 2024
  4. changed the title [-]item not moved (to alt space) when colliding fails with another object[/-] [+]item not moved (to alt position) when colliding fails with an object[/+] on Oct 15, 2024
  5. Hickays commented on Oct 16, 2024

    @Hickays
    Author

    很确定这是另一个错误的重复。与鼠标延迟无关。它试图与下面的项目发生碰撞,并且当第一个项目无法碰撞时无法使用替代项目移动。

    另外,将示例修改为默认布局问题也会有所帮助,这样我就不必这样做了。

    Oh, thanks for the reply. I apologize for my poor English and for not being able to accurately finding the repeat issue.

  6. BrokeItSafely commented on Mar 30, 2026

    @BrokeItSafely

    I ran into the same issue on v12.4.2 with column: 48, cellHeight: 10, float: true. Traced it through the source — here's the root cause and a proposed fix.

    Just a heads-up: Vibe-coded with Opus 4.6 using gridstack + svelte for UI/UX but relevant (Proposed fix is all Opus 4.6):

    Root Cause

    In gridstack-engine.js, the directionCollideCoverage() method has a hard-coded >50% directional coverage threshold (line ~186):

    let overMax = 0.5; // need >50%

    This is called from moveNode() (line ~970) only during active drag:

    let collide = activeDrag ? this.directionCollideCoverage(node, o, collides) : collides[0];

    When the dragged widget overlaps a target by less than 50%, directionCollideCoverage returns undefined, and moveNode silently rejects the position update:

    } else {
        needToMove = false; // we didn't cover >50% for a move, skip...
    }

    Why it's asymmetric:

    • Dragging into empty space — no collision, collides.length === 0, so the position updates immediately at every cell increment
    • Dragging into an occupied cell — collision detected, but the 50% threshold blocks the move until you drag >50% of the target widget's height into its area

    With small cellHeight (10–20px), this means you can drag smoothly upward into empty space, but dragging downward into an adjacent widget requires 50%+ of that widget's pixel height before anything happens — easily 100–300px of "dead zone."

    Suggested Fix

    Make the threshold configurable via GridStackOptions, defaulting to 0.5 for backward compatibility:

    // types.ts — add to GridStackOptions
    /** Coverage threshold (0-1) for directional collision during drag. Default: 0.5 */
    collisionCoverage?: number;
    // gridstack-engine.js — directionCollideCoverage()
    let overMax = this.opts?.collisionCoverage ?? 0.5;

    Alternative: auto-adjust for float mode

    If a new option isn't desirable, the threshold could automatically drop to 0 when float: true, since overlapping is explicitly allowed in that mode:

    let overMax = this.float ? 0 : 0.5;

    Current Workaround

    We monkey-patch directionCollideCoverage after GridStack.init() to return the first non-locked collision immediately:

    const engine = grid.engine;
    engine.directionCollideCoverage = function(node, o, collides) {
        for (const n of collides) {
            if (!n.locked) {
                o.collide = n;
                return n;
            }
        }
        return undefined;
    };

    Trade-offs of this workaround:

    • ✅ Drag is buttery smooth in all directions
    • ✅ Collision push/swap still works
    • ⚠️ Loses directional awareness (original computes horizontal vs vertical overlap based on drag direction)
    • ⚠️ Loses "best match" selection when multiple widgets collide (returns first instead of highest-coverage)
    • ⚠️ Could cause more sensitive/twitchy swaps in non-float mode

    A first-class configurable threshold would preserve the directional logic while letting users tune the responsiveness.

    Environment: GridStack 12.4.2, SvelteKit + Svelte 5, column: 48, cellHeight: 10, float: true, margin: 2

  7. adumesny commented on Mar 30, 2026

    @adumesny
    Member

    With small cellHeight (10–20px), this means you can drag smoothly upward into empty space, but dragging downward into an adjacent widget requires 50%+ of that widget's pixel height before anything happens — easily 100–300px of "dead zone."

    it's not a dead zone, and yes you should cover the (larger) target widget by >50% before moving it out otherwise it wil always push it by 1 row and you could never push it past.

    actually now that I write it down it should push and jump past if over 50% of larger object. so always move (if it can) by 50% row coverage.

  8. added a commit that references this issue on Sep 28, 2026
    1db9092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions