Skip to content

fix(cdk/drag-drop): throw if drop list or handle are set on a non-element node #20668

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

Merged
merged 1 commit into from
Oct 2, 2020

Conversation

crisbeto
Copy link
Member

Currently if a cdkDropList or cdkDragHandle is attached to a non-element node, a cryptic error is thrown. These changes add a proper error, similar to the one we have on cdkDrag.

Fixes #13540.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Sep 28, 2020
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 28, 2020
@crisbeto crisbeto force-pushed the 13540/drag-drop-assertions branch 2 times, most recently from f877ea3 to 9dd5b78 Compare September 28, 2020 18:08
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Sep 28, 2020
@Achilles1515
Copy link

@crisbeto
What is the following check doing?
(typeof ngDevMode === 'undefined' || ngDevMode)

If I understand ngDevMode correctly,

typeof ngDevMode === 'undefined' will be true when in production mode.
ngDevMode will be true (NgDevModePerfCounters object) when in development mode.

So this is specifically checking for if ngDevMode has been manually set to false?

@crisbeto
Copy link
Member Author

The typeof check is necessary, because ngDevMode might not be defined in ViewEngine apps. JS in strict mode throws an error when trying to access an undefined global variable.

@Achilles1515
Copy link

So (typeof ngDevMode === 'undefined' || ngDevMode) is expected to return:

VE (maybe just some...?)
true

IVY
prod - true
dev - true

What is the purpose?

@crisbeto
Copy link
Member Author

It'll always be true for VE and in Ivy it'll get replaced to (typeof null === 'undefined' || null) which Terser is smart enough to remove, because it's considered dead code.

@Achilles1515
Copy link

Ah, okay. So ngDevMode is like a #define C macro during compilation.
Great timing on this article, too.

Thanks for the response.

…ment node

Currently if a `cdkDropList` or `cdkDragHandle` is attached to a non-element node,
a cryptic error is thrown. These changes add a proper error, similar to the one we have
on `cdkDrag`.

Fixes angular#13540.
@crisbeto crisbeto force-pushed the 13540/drag-drop-assertions branch from 9dd5b78 to 36c1290 Compare October 2, 2020 08:49
@mmalerba mmalerba added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Oct 2, 2020
@mmalerba mmalerba merged commit d4b505a into angular:master Oct 2, 2020
crisbeto added a commit to crisbeto/material2 that referenced this pull request Oct 7, 2020
I left in some invalid code in the `drag-drop` demo while working on angular#20668 which is throwing an error now.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Oct 7, 2020
I left in some invalid code in the `drag-drop` demo by accident while working on angular#20668 which is throwing an error now.
wagnermaciel pushed a commit that referenced this pull request Oct 8, 2020
I left in some invalid code in the `drag-drop` demo by accident while working on #20668 which is throwing an error now.
@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 Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cdk/drag-drop Cannot read property 'nativeElement' of undefined MatTable
5 participants