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(DragDropModule): Dependency Injection issue with CdkDrag combined with CdkVirtualScroll after upgrade #28744

Closed
1 task done
sdoyle0 opened this issue Mar 19, 2024 · 3 comments · Fixed by #28750
Closed
1 task done
Assignees
Labels
area: cdk/drag-drop P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@sdoyle0
Copy link

sdoyle0 commented Mar 19, 2024

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

17.2.1

Description

I think the changes in PR 28633 (a fix for #28614) may have caused a dependency injection issue when combining virtual scroll and drag and drop. I've setup a very minimal StackBlitz example to show the issue here: https://stackblitz.com/edit/f2xpkk. If you load the example as it is currently with version 17.2.2, you'll see the following stack trace:
vendor.js:47027 ERROR NullInjectorError: R3InjectorError(Standalone[CdkVirtualScrollAppendOnlyExample])[InjectionToken CDK_DRAG_PARENT -> InjectionToken CDK_DRAG_PARENT -> InjectionToken CDK_DRAG_PARENT]:
NullInjectorError: No provider for InjectionToken CDK_DRAG_PARENT!
at NullInjector.get (vendor.js:44290:21)
at R3Injector.get (vendor.js:44741:27)
at R3Injector.get (vendor.js:44741:27)
at R3Injector.get (vendor.js:44741:27)
at ChainedInjector.get (vendor.js:55693:32)
at lookupTokenUsingModuleInjector (vendor.js:46282:31)
at getOrCreateInjectable (vendor.js:46328:10)
at ɵɵdirectiveInject (vendor.js:49755:17)
at ɵɵinject (vendor.js:43467:59)
at inject (vendor.js:43550:10

Reproduction

StackBlitz link: https://stackblitz.com/edit/f2xpkk
Steps to reproduce:

  1. Open the StackBlitz and see the console error
  2. If you update all the Angular versions in the package file to 17.2.1 and reload, the error is no longer present

Expected Behavior

No stack trace error and page loads successfully

Actual Behavior

Console errors about dependency injection prevent the component from loading completely

Environment

  • Angular: 17.2.2 (and 17.3.0)
  • CDK/Material: 17.2.2 (and 17.3.0)
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows
@sdoyle0 sdoyle0 added the needs triage This issue needs to be triaged by the team label Mar 19, 2024
@mmalerba mmalerba added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: cdk/drag-drop and removed needs triage This issue needs to be triaged by the team labels Mar 19, 2024
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 20, 2024
…eholder

Fixes a regression from angular#28633 where using `cdkDragPlaceholder` or `cdkDragPreview` without a `cdkDrag` would throw. Technically this is a no-op, but it appears that folks started depending on the old behavior so these changes bring it back.

Fixes angular#28744.
@crisbeto
Copy link
Member

I've sent a fix at #28750, but I wanted to note that the placeholder in your example does nothing because there's no cdkDrag around it.

@sdoyle0
Copy link
Author

sdoyle0 commented Mar 20, 2024

Thanks! That was intentional in the example. The application where I found this is much larger and has the additional elements, but I was trying to get the sample down to the bare minimum that would reproduce it

crisbeto added a commit that referenced this issue Mar 20, 2024
…eholder (#28750)

Fixes a regression from #28633 where using `cdkDragPlaceholder` or `cdkDragPreview` without a `cdkDrag` would throw. Technically this is a no-op, but it appears that folks started depending on the old behavior so these changes bring it back.

Fixes #28744.
crisbeto added a commit that referenced this issue Mar 20, 2024
…eholder (#28750)

Fixes a regression from #28633 where using `cdkDragPlaceholder` or `cdkDragPreview` without a `cdkDrag` would throw. Technically this is a no-op, but it appears that folks started depending on the old behavior so these changes bring it back.

Fixes #28744.

(cherry picked from commit 9343131)
@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 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/drag-drop 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.

3 participants