Skip to content

fix(table): use default change detection strategy on table #15440

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

andrewseguin
Copy link
Contributor

[Note: This change includes formatting changes as well as the actual code changes. The only change is that Default change detection strategy will be used instead of OnPush for table and row components.]

This resolves an issue with Ivy where change detection was not reflecting binding changes made to the row and cell templates in the component declaring the table.

In View Engine, change detection for a dynamically created view runs in two cases:

  1. When the view in which it was inserted is checked
  2. When the view in which it was declared is checked

As a result, if a dynamic view is inserted into an OnPush component, that view is not actually checked only "on push". It is also checked as often as its declaration view is checked (even if the insertion view is explicitly detached from change detection).

For this reason, marking MatTable as "OnPush" doesn't have much of an effect. It is built almost entirely of views that are declared elsewhere, so its change detection frequency is dependent on those declaration views. It also doesn't have any bindings inside its own view that would be protected by "OnPush", so marking it this way is effectively a noop and can be removed without performance regressions.

In Ivy, this change detection loophole has been closed, so declaration views can no longer de-optimize OnPush components. This means bindings inherited from declaration views aren't updated by default if MatTable is OnPush (the embedded view would need to be marked dirty explicitly).

To avoid breaking changes when we transition to Ivy, it makes more sense to perpetuate the current behavior by removing the "OnPush" marker. As delineated earlier, this has no impact on View Engine. For Ivy, it would ensure bindings inherited from the declaration view are still checked by default.

@andrewseguin andrewseguin added the target: minor This PR is targeted for the next minor release label Mar 11, 2019
@andrewseguin andrewseguin requested review from jelbourn and kara March 11, 2019 18:28
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Mar 11, 2019
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM

@andrewseguin andrewseguin force-pushed the table-default-change-detection-strategy branch from 19dfa99 to ba3d72c Compare March 11, 2019 22:42
@kara kara added the pr: lgtm label Mar 12, 2019
@kara
Copy link
Contributor

kara commented Mar 12, 2019

caretaker: FYI have @jelbourn's verbal approval for this as well

This resolves an issue with Ivy where change detection was not reflecting binding changes made to the row and cell templates in the component declaring the table.

In View Engine, change detection for a dynamically created view runs in two cases:
        1) When the view in which it was inserted is checked
        2) When the view in which it was declared is checked

As a result, if a dynamic view is inserted into an OnPush component, that view is not actually checked only "on push". It is also checked as often as its declaration view is checked (even if the insertion view is explicitly detached from change detection).

For this reason, marking `MatTable` as "OnPush" doesn't have much of an effect. It is built almost entirely of views that are declared elsewhere, so its change detection frequency is dependent on those declaration views. It also doesn't have any bindings inside its own view that would be protected by "OnPush", so marking it this way is effectively a noop and can be removed without performance regressions.

In Ivy, this change detection loophole has been closed, so  declaration views can no longer de-optimize OnPush components. This means bindings inherited from declaration views aren't updated by default if `MatTable` is OnPush (the embedded view would need to be marked dirty explicitly).

To avoid breaking changes when we transition to Ivy, it makes more sense to perpetuate the current behavior by removing the "OnPush" marker. As delineated earlier, this has no impact on View Engine. For Ivy, it would ensure bindings inherited from the declaration view are still checked by default.
@andrewseguin andrewseguin force-pushed the table-default-change-detection-strategy branch from ba3d72c to 5379c17 Compare March 12, 2019 17:54
@mmalerba mmalerba added target: major This PR is targeted for the next major release P2 The issue is important to a large percentage of users, with a workaround action: merge The PR is ready for merge by the caretaker and removed target: minor This PR is targeted for the next minor release labels Mar 12, 2019
@mmalerba mmalerba merged commit f82259b into angular:master Mar 12, 2019
andrewseguin added a commit to andrewseguin/components that referenced this pull request Mar 12, 2019
Suresh918 pushed a commit to Suresh918/material2 that referenced this pull request Apr 15, 2019
…5440)

This resolves an issue with Ivy where change detection was not reflecting binding changes made to the row and cell templates in the component declaring the table.

In View Engine, change detection for a dynamically created view runs in two cases:
        1) When the view in which it was inserted is checked
        2) When the view in which it was declared is checked

As a result, if a dynamic view is inserted into an OnPush component, that view is not actually checked only "on push". It is also checked as often as its declaration view is checked (even if the insertion view is explicitly detached from change detection).

For this reason, marking `MatTable` as "OnPush" doesn't have much of an effect. It is built almost entirely of views that are declared elsewhere, so its change detection frequency is dependent on those declaration views. It also doesn't have any bindings inside its own view that would be protected by "OnPush", so marking it this way is effectively a noop and can be removed without performance regressions.

In Ivy, this change detection loophole has been closed, so  declaration views can no longer de-optimize OnPush components. This means bindings inherited from declaration views aren't updated by default if `MatTable` is OnPush (the embedded view would need to be marked dirty explicitly).

To avoid breaking changes when we transition to Ivy, it makes more sense to perpetuate the current behavior by removing the "OnPush" marker. As delineated earlier, this has no impact on View Engine. For Ivy, it would ensure bindings inherited from the declaration view are still checked by default.
jelbourn added a commit to jelbourn/components that referenced this pull request Jul 15, 2019
This resolves an issue with ivy where the template content would be
checked out of sync with the tab view. See angular#15440 for additional
context.
jelbourn added a commit to jelbourn/components that referenced this pull request Jul 15, 2019
This resolves an issue with ivy where the template content would be
checked out of sync with the tab view. See angular#15440 for additional
context.
jelbourn added a commit that referenced this pull request Jul 17, 2019
This resolves an issue with ivy where the template content would be
checked out of sync with the tab view. See #15440 for additional
context.
jelbourn added a commit that referenced this pull request Sep 6, 2019
This resolves an issue with ivy where the template content would be
checked out of sync with the tab view. See #15440 for additional
context.
@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 10, 2019
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 P2 The issue is important to a large percentage of users, with a workaround target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants