Skip to content

fix(drag-drop): detect changes on custom preview/placeholder before measuring #18698

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

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Mar 3, 2020

When a custom preview/placeholder is created, its dimensions are measured so that they can be used while sorting. The problem is that we weren't detecting changes after creation which can cause the dimensions to be incorrect, if they change based on a data binding. These changes check for changes after inserting the embedded view.

Fixes #18622.

…easuring

When a custom preview/placeholder is created, its dimensions are measured so that they can be used while sorting. The problem is that we weren't detecting changes after creation which can cause the dimensions to be incorrect, if they change based on a data binding. These changes check for changes after inserting the embedded view.

Fixes angular#18622.
@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 Mar 3, 2020
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Mar 3, 2020
@@ -884,6 +884,7 @@ export class DragRef<T = any> {
if (previewTemplate) {
const viewRef = previewConfig!.viewContainer.createEmbeddedView(previewTemplate,
previewConfig!.context);
viewRef.detectChanges();
Copy link
Member

Choose a reason for hiding this comment

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

Rather than directly calling detectChanges, couldn't we instead defer measuring until Angular completes the change detection it needs to do anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

Almost none of the drag&drop events trigger change detection so we can't really depend on it since it can happen at any time for other reason. This only detects on a small chunk of the tree anyway.

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 lgtm action: merge The PR is ready for merge by the caretaker labels Mar 6, 2020
@andrewseguin andrewseguin merged commit e87de13 into angular:master Mar 12, 2020
andrewseguin pushed a commit that referenced this pull request Mar 12, 2020
…easuring (#18698)

When a custom preview/placeholder is created, its dimensions are measured so that they can be used while sorting. The problem is that we weren't detecting changes after creation which can cause the dimensions to be incorrect, if they change based on a data binding. These changes check for changes after inserting the embedded view.

Fixes #18622.

(cherry picked from commit e87de13)
@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 12, 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: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngClass behaving differently than regular classes with cdk-drag-drop
4 participants