Open Bug 1896323 Opened 2 years ago Updated 2 years ago

When dragging between windows, the "dragend" event in the source window does not wait for the "drop" event to finish in the destination window

Categories

(Core :: DOM: Copy & Paste and Drag & Drop, defect)

Firefox 128
defect

Tracking

()

UNCONFIRMED

People

(Reporter: alexreardon, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Steps to reproduce:

  1. drag a draggable element from one window (source window) to another (destination window)
  2. ✅ the "drop" event in destination window fires before the "dragend" event in source window (all good so far)
  3. 🐛 The "dragend" event in source window does not wait for the "drop" event in destination window to finish before being fired

[Reproduction url]

  1. drag the draggable element from https://dzlcry.csb.app/ to another window with the same url: https://dzlcry.csb.app/
  2. observe the timings in the console

Source code of reproduction case: https://codesandbox.io/p/sandbox/cross-document-event-timing-bug-for-bug-report-dzlcry?file=%2Fsrc%2Findex.ts%3A36%2C22

Actual results:

The "dragend" event in the source window does not wait for the "drop" event in the destination window to finish being processed.

Expected results:

The "dragend" event in the source window should not fire until the "drop" event in destination window has finished being processed.

  • Chrome@124.0 waits for the "drop" event in the destination window to finish before firing the "dragend" event in the source window.
  • Safari@17.4.1 has the same bug as Firefox (will raise a bug report soon)

According to the spec processing model the "drop" event should finish before the "dragend" event is fired.

Component: Untriaged → DOM: Copy & Paste and Drag & Drop
Product: Firefox → Core

Hi Alex, I don't see where the spec asks us to wait for the "drop" event to be finished first. AFAICT, "dragend" event is expected to be fired after the user ends the drag-and-drop operation. There's a step in the spec starts with Otherwise, if the user ended the drag-and-drop operation, and "dragend" is #2 of this step.

Can you clarify this a bit more? Thanks

Flags: needinfo?(alexreardon)

Hi Sean,

Thanks for engaging with this issue!

I think that the spec requires the "drop" event to be finished before "dragend" is fired for two reasons:

  1. Step 4.3 (handing "dragend") requires information from a completed "drop" event (4.1b.3)
  2. Reasoning based on the language used in the spec

Reason 1: required information

Step 4. of the processing model covers what to do when a drag operation is finishing:

4.1 - what do do on failure (4.1.1, 4.1.2 and 4.1.3)
4.1b - what to do on success (4.1b.1, 4.1b.2 and 4.1b.3) (there is no 4.1b but I added a 4.1b for clarity. I'm speaking too "Otherwise, the drag operation might be a success; run these substeps:")

Step 4.2 of the processing model:

Fire a DND event named dragend at the source node.

Step 4.3 of the processing model:

Run the appropriate steps from the following list as the default action of the dragend event:

Step 4.3 involves a decision that is impacted the "current drag operation".

If dropped is false or if the current drag operation is "none"...

4.1b.3 talks about what to do with the dropEffect and behaviour if the "drop" event is cancelled:

If the event is canceled, set the current drag operation to the value of the dropEffect attribute of the DragEvent object's dataTransfer object as it stood after the event dispatch finished.

The "drop" event needs to be finished before the browser can know if the "drop" event was cancelled. If the "drop" event is cancelled, then the "current drag operation" can be impacted. So for the processing in "dragend" to know the "current drag operation", it would need to wait for "drop" to finish.

Reason 2: language used

Step 4. of the processing model covers what to do when a drag operation is finishing:

Otherwise, if the user ended the drag-and-drop operation (e.g. by releasing the mouse button in a mouse-driven drag-and-drop interface), or if the drag event was canceled, then this will be the last iteration. Run the following steps, then stop the drag-and-drop operation
(emphasis added)

I think the natural reading of "run the following steps" is that an ordered list of steps need to be done sequentially and not in parallel. If they were intended to be done in parallel, then I think that could have been made clear with explicit language, or with the use of an unordered list rather than an ordered list. To me, "steps" also implies a sequence (physical steps are one after the other)

Cheers

Flags: needinfo?(alexreardon)
Severity: -- → S3
You need to log in before you can comment on or make changes to this bug.