question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

modifying styles during dragstart handler causes Chrome to fire dragend immediately on start

See original GitHub issue

EDIT: not actually unique to captureDraggingState. It’s for any CSS change applied while dragstart is still being handled.

https://bugs.chromium.org/p/chromium/issues/detail?id=168544

Workaround

Make any changes that cause style changes (e.g. firing actions that cause a class to be applied…) in a setTimeout(() => {}, 0) wrapper.

Describe the bug

Usually with the HTML5 backend, one 'dragstart' event fires when you drag something, and one 'dragend' fires when you drop it.

Now, in Chrome, at least in v67, when you have captureDraggingState: true, this is messed up. It goes:

  • mouse down to drag an item, move it;
    • 'dragstart'
    • 'dragend' immediately after that
  • later, drop the item:
    • no events fire

Because of this, you can’t actually drag anything – it is immediately dropped. Workaround is to drop IE11 DragLayer support by using the default value, false.

To Reproduce Steps to reproduce the behavior:

  1. On any example drag source, run connectDragPreviewwith{ captureDraggingState: true }` as its options.
  2. Using Chrome dev tools, run monitorEvents(document.body, 'dragstart') and monitorEvents(document.body, 'dragend').
  3. Try to drag the source.
  4. Watch the console output.
  5. Also, observe that nothing happens under your mouse cursor, the drag barely happens at all.

Expected behavior

There should be no 'dragend' until you drop, and you should be able to drag things.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 67

It works fine in Firefox 60 on Windows.

Additional context

Technically I am using angular-skyhook, but the code responsible for passing an Element/Node through to a backend with options is almost identical, even slightly simpler with no need for wrapConnectorHooks:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:8

github_iconTop GitHub Comments

2reactions
Pavel910commented, Jul 9, 2018

@cormacrelf I ran into this problem today, in my case I have a list of draggable items (like a drawer with items), and when I start dragging I hide the drawer via CSS - at this point dragend fires and breaks dragging.

I managed to bypass this behavior by using setTimeout to update CSS. It’s an ugly hack but solved my problem until a real fix lands.

1reaction
Chetan11-devcommented, Aug 18, 2021

Code Example

   useEffect(() => {
        if (isDragging) {
            setTimeout(() => {
                ref.current!.style.display = 'none'
            }, 0)
        }
    }, [isDragging])


    return (
        <div ref={ref} className={classNames('side-panel left-0', Classes['left-side-panel'])}>
            {ChildrenComponent}
        </div>
    )
Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML5 dragend event firing immediately - Stack Overflow
This is a known chrome issue. Problem is, as Joerg mentions that you manipulates the dom on dragstart.
Read more >
modifying styles during dragstart handler causes Chrome to fire ...
mouse down to drag an item, move it;. 'dragstart'; 'dragend' immediately after that. later, drop the item: no events fire.
Read more >
26699 – [Win] HTML5 Drag and drop, dragend is not fired ...
This makes cleaning up from drag operations very hard. This happens on Safari 4 and Chrome on Windows 7. It works fine for...
Read more >
Using the HTML5 Drag and Drop API - web.dev
The HTML5 Drag and Drop API means that we can make almost any element on our page draggable. In this post we'll explain...
Read more >
HTMLElement: dragend event - Web APIs | MDN
The dragend event is fired when a drag operation is being ended (by releasing a mouse button or hitting the escape key).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found