Skip to content

bug(cdkDrogList): dragRef._previewRect is set after scroll #24497

Closed
@xiaohanw-google

Description

@xiaohanw-google

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I got the error when dragging a cdkDrag element with a boundary element:

Uncaught TypeError: Cannot read properties of undefined (reading 'height')
at DragRef._getConstrainedPointerPosition (/unmappedjs/third_party/javascript/angular_components/src/cdk/drag-drop/drag-ref.js:879:59)
at DragRef._sortFromLastPointerPosition (/unmappedjs/third_party/javascript/angular_components/src/cdk/drag-drop/drag-ref.js:428:50)
at eval (/unmappedjs/third_party/javascript/angular_components/src/cdk/drag-drop/drop-list-ref.js:751:34)
at Array.forEach ()
at SafeSubscriber.eval [as _next] (/unmappedjs/third_party/javascript/angular_components/src/cdk/drag-drop/drop-list-ref.js:746:42)
at SafeSubscriber.__tryOrUnsub (/unmappedjs/third_party/javascript/rxjs/src/internal/Subscriber.js:264:16)
at SafeSubscriber.next (/unmappedjs/third_party/javascript/rxjs/src/internal/Subscriber.js:202:22)
at Subscriber._next (/unmappedjs/third_party/javascript/rxjs/src/internal/Subscriber.js:142:26)
at Subscriber.next (/unmappedjs/third_party/javascript/rxjs/src/internal/Subscriber.js:106:18)
at Subject.next (/unmappedjs/third_party/javascript/rxjs/src/internal/Subject.js:59:25)
at HTMLDocument.handler (/unmappedjs/third_party/javascript/angular_components/src/cdk/drag-drop/drag-drop-registry.js:141:61)
at _ZoneDelegate.invokeTask (/unmappedjs/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.js:428:31)
at Zone.runTask (/unmappedjs/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.js:197:47)
at ZoneTask.invokeTask [as invoke] (/unmappedjs/third_party/javascript/angular2/rc/packages/zone.js/lib/zone.js:510:34)
at invokeTask (/unmappedjs/third_party/javascript/angular2/rc/packages/zone.js/lib/common/events.js:78:18)

After a little logging I believe that is because _listenToScrollEvents is called after _pointerMove, so in _listenToScrollEvents the _previewRect is undefined.

Reproduction

Steps to reproduce:

  1. Open the StackBlitz: https://stackblitz.com/edit/components-issue-szdbsj?file=src%2Fapp%2Fexample-component.html
  2. Make sure the page can be scrolled and scroll to the bottom of the page: https://screenshot.googleplex.com/Bzf52W2SPxds6Jj
  3. Try dragging the last element, i.e., 5555
  4. You'll get this error: https://screenshot.googleplex.com/57X54dJ42LPRZku

Expected Behavior

The element can be dragged without error.

Actual Behavior

There is an error due to undefined _previewRect.

Environment

  • Angular:
  • CDK/Material:
  • Browser(s):
  • Operating System (e.g. Windows, macOS, Ubuntu):

Metadata

Metadata

Assignees

Labels

GThis is is related to a Google internal issueP3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/drag-drop

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions