Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task
xiaohanw-google opened this issue Mar 1, 2022 · 1 comment · Fixed by #24498
Closed
1 task

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

xiaohanw-google opened this issue Mar 1, 2022 · 1 comment · Fixed by #24498
Assignees
Labels
area: cdk/drag-drop G This is is related to a Google internal issue P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@xiaohanw-google
Copy link

xiaohanw-google commented Mar 1, 2022

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):
@xiaohanw-google xiaohanw-google added the needs triage This issue needs to be triaged by the team label Mar 1, 2022
@crisbeto crisbeto self-assigned this Mar 1, 2022
@crisbeto crisbeto added area: cdk/drag-drop G This is is related to a Google internal issue has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Mar 1, 2022
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 1, 2022
Fixes a null pointer exception that can happen if the page is scrolled before the user has scrolled the minimum distance. The problem was that we were expecting for the dimensions to be defined by the time the user has had the chance to scroll, but in some cases that can be circumvented.

These changes move the measurement to a getter method so that they're guaranteed to be available when they are requested.

Fixes angular#24497.
crisbeto added a commit that referenced this issue Mar 1, 2022
#24498)

Fixes a null pointer exception that can happen if the page is scrolled before the user has scrolled the minimum distance. The problem was that we were expecting for the dimensions to be defined by the time the user has had the chance to scroll, but in some cases that can be circumvented.

These changes move the measurement to a getter method so that they're guaranteed to be available when they are requested.

Fixes #24497.

(cherry picked from commit 37be099)
crisbeto added a commit that referenced this issue Mar 1, 2022
#24498)

Fixes a null pointer exception that can happen if the page is scrolled before the user has scrolled the minimum distance. The problem was that we were expecting for the dimensions to be defined by the time the user has had the chance to scroll, but in some cases that can be circumvented.

These changes move the measurement to a getter method so that they're guaranteed to be available when they are requested.

Fixes #24497.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 1, 2022
forsti0506 pushed a commit to forsti0506/components that referenced this issue Apr 3, 2022
angular#24498)

Fixes a null pointer exception that can happen if the page is scrolled before the user has scrolled the minimum distance. The problem was that we were expecting for the dimensions to be defined by the time the user has had the chance to scroll, but in some cases that can be circumvented.

These changes move the measurement to a getter method so that they're guaranteed to be available when they are requested.

Fixes angular#24497.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/drag-drop G This is is related to a Google internal issue P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants