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(cdk/drag-drop): error when ngDevMode is undefined #29633

Closed
1 task done
kfrederix opened this issue Aug 23, 2024 · 1 comment · Fixed by #29634
Closed
1 task done

bug(cdk/drag-drop): error when ngDevMode is undefined #29633

kfrederix opened this issue Aug 23, 2024 · 1 comment · Fixed by #29634
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

@kfrederix
Copy link

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

18.0.6

Description

Since version 18.1.0, a change got introduced in drag-ref.ts which checks the ngDevMode without taking into account that it could be undefined.

In such cases (when ngDevMode is undefined) this results in an error:

ReferenceError: ngDevMode is not defined
    at DragRef._startDragSequence (drag-drop.mjs:957:82)

It got introduced with version 18.1.0 by feat(cdk/drag-drop): add mixed orientation support

After some investigation, I noticed that in other places within the angular codebase, we always make sure that the code is able to deal with that.
e.g.

if ("undefined" !== typeof ngDevMode && ngDevMode) { ... }

So even though this should only happen for some more exotic use-cases, it looks to me like it is known to the Angular team that this can occur (ngDevMode being undefined) and it should be taken into account.
(I also found this commit which seems to confirm it)

Reproduction

StackBlitz link: https://stackblitz.com/edit/ddzadm?file=angular.json

Steps to reproduce:

  1. Try dragging one of the items in the list
  2. Observe: drag does not work + error in JS console

NOTE:
To set up this repro case on StackBlitz, I have "externalized" the Angular packages by listing them as externalDependencies in the angular.json file, and added an importmap in index.html to resolve the packages at runtime (using @esm-bundle/angular - see Joel Denning's blog post for more info about this).
I fully realize that this an exotic setup, but it simulates the situation where multiple Angular micro-frontends are "sharing" the same angular packages.

Expected Behavior

No error, ngDevMode should be assumed falsy when it's undefined.

Actual Behavior

ReferenceError: ngDevMode is not defined
    at DragRef._startDragSequence (drag-drop.mjs:957:82)

Environment

Angular CLI: 18.2.1
Node: 20.12.2
Package Manager: pnpm 9.7.1
OS: win32 x64

Angular: 18.2.1
... animations, build, cdk, cli, common, compiler, compiler-cli
... core, forms, language-service, material, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1802.0
@angular-devkit/build-angular 18.2.1
@angular-devkit/core 18.2.1
@angular-devkit/schematics 18.2.1
@schematics/angular 18.2.1
rxjs 7.8.1
typescript 5.5.4
webpack 5.91.0
zone.js 0.14.10

@kfrederix kfrederix added the needs triage This issue needs to be triaged by the team label Aug 23, 2024
@crisbeto crisbeto self-assigned this Aug 23, 2024
@crisbeto crisbeto 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 Aug 23, 2024
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 23, 2024
Fixes that the drag&drop module wasn't checking for `ngDevMode` correctly.

Fixes angular#29633.
crisbeto added a commit that referenced this issue Aug 23, 2024
Fixes that the drag&drop module wasn't checking for `ngDevMode` correctly.

Fixes #29633.

(cherry picked from commit 2f1fe03)
@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 Sep 23, 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.

2 participants