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

fix(core): Switch emitDistinctChangesOnlyDefaultValue to true #41121

Closed

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Mar 8, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Mar 8, 2021
@pullapprove pullapprove bot requested a review from AndrewKushnir March 8, 2021 19:24
@mhevery mhevery added the target: major This PR is targeted for the next major release label Mar 8, 2021
@mhevery
Copy link
Contributor Author

mhevery commented Mar 8, 2021

presubmit

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@mhevery thanks for switching the default value!

It looks like there are few more places where the comments (that refer to v12) should be updated:

@mhevery should we mark this PR as a breaking change and add the "BREAKING CHANGE" note to the commit message as well? The previous PR where this change was introduced was backwards-compatible, but flipping the default would trigger a new codepath for all apps (that might potentially be breaking).

Also it looks like there is one legit failing test on CI, could you please have a look?

Thank you.

packages/compiler/src/core.ts Outdated Show resolved Hide resolved
Comment on lines 109 to 111
// Stores the default value of `emitDistinctChangesOnly` when the `emitDistinctChangesOnly` is not
// explicitly set. This value will be changed to `true` in v12.
// TODO(misko): switch the default in v12 to `true`. See: packages/compiler/src/core.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Stores the default value of `emitDistinctChangesOnly` when the `emitDistinctChangesOnly` is not
// explicitly set. This value will be changed to `true` in v12.
// TODO(misko): switch the default in v12 to `true`. See: packages/compiler/src/core.ts
// Stores the default value of `emitDistinctChangesOnly` when the `emitDistinctChangesOnly` is not
// explicitly set.

@mhevery mhevery force-pushed the emitDistinctChangesOnlyDefaultValue branch from d33e8e9 to f0f1139 Compare March 8, 2021 20:57
@pullapprove pullapprove bot requested a review from JoostK March 8, 2021 20:57
@@ -237,9 +237,6 @@ export interface R3DeclareQueryMetadata {
/**
* True to only fire changes if there are underlying changes to the query.
*/
// TODO(misko): This will become `true` be default in v12. `QueryList.changes` would fire even if
// no changes to the query list were detected. This is not ideal, as changes should only fire if
// the `QueryList` actually materially changed.
emitDistinctChangesOnly?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Are there plans to deprecate this, or do we want to keep this around?

Copy link
Contributor Author

@mhevery mhevery Mar 8, 2021

Choose a reason for hiding this comment

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

I think we should delete this global flag after everything lands and things are quite. Deleting the flag now, would make rollback difficult if we run into issues.

Copy link
Member

Choose a reason for hiding this comment

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

I see this comment may have been a bit out of place; I thought this was the public facing metadata object for ContentQuery/ViewQuery; I meant the deprecation of emitDistinctChangesOnly as it can be configured by developers for ContentQuery/ViewQuery. Do we want to keep supporting it being set to false? My vote would be to deprecate the flag now, so that it's clear that using emitDistinctChangesOnly: false to mitigate the breaking change is only to buy the developer some extra time in their migration, and that the option will be going away in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mhevery mhevery force-pushed the emitDistinctChangesOnlyDefaultValue branch 2 times, most recently from 60cde89 to e976dd4 Compare March 8, 2021 23:05
@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime labels Mar 8, 2021
@ngbot ngbot bot modified the milestone: Backlog Mar 8, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the feedback @mhevery 👍

I think we can update the commit message to add the "BREAKING CHANGE" note above the commit description, so that it goes into the breaking changes section of the CHANGELOG with all the details (that'd help migrate apps over):

fix(core): Switch `emitDistinctChangesOnlyDefaultValue` to true

BREAKING CHANGE:

The previous implementation would fire changes `QueryList.changes.subscribe`
whenever the `QueryList` was recomputed. This resulted in an artificially
high number of change notifications, as it is possible that recomputing
`QueryList` results in the same list. When the `QueryList` gets recomputed
is an implementation detail, and it should not be the thing that determines
how often change event should fire.

...

If I understand correctly, @JoostK proposes to add the @deprecated JSDoc annotation to the emitDistinctChangesOnly flag of the query decorator arguments, so that we can remove it altogether later (in v13 or v14). For completeness, we can probably do that in the same commit and extend the "BREAKING CHANGE" note to mention this deprecation.

It looks like CI has some failing tests as well, which are related to the changes in this PR.

Thank you.

@mhevery mhevery force-pushed the emitDistinctChangesOnlyDefaultValue branch from e976dd4 to dd0ea2f Compare March 9, 2021 00:50
@mary-poppins
Copy link

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@mhevery I've just added a couple more comments, please see below.

I think we should also add a deprecation notice to this page: https://angular.io/guide/deprecations#angularcore (the aio/content/guide/deprecations.md file).

packages/core/src/metadata/di.ts Outdated Show resolved Hide resolved
packages/core/src/metadata/di.ts Show resolved Hide resolved
@mhevery mhevery force-pushed the emitDistinctChangesOnlyDefaultValue branch from dd0ea2f to 1054319 Compare March 10, 2021 19:31
@mary-poppins
Copy link

You can preview 1054319 at https://pr41121-1054319.ngbuilds.io/.

@mhevery mhevery force-pushed the emitDistinctChangesOnlyDefaultValue branch 2 times, most recently from 0e32b8c to 28e117c Compare March 10, 2021 20:17
BREAKING CHANGE:

Switching default of `emitDistinctChangesOnlyDefaultValue`
which changes the default behavior and may cause some applications which
rely on the incorrect behavior to fail.

`emitDistinctChangesOnly` flag has also been deprecated and will be
removed in a future major release.

The previous implementation would fire changes `QueryList.changes.subscribe`
whenever the `QueryList` was recomputed. This resulted in an artificially
high number of change notifications, as it is possible that recomputing
`QueryList` results in the same list. When the `QueryList` gets recomputed
is an implementation detail, and it should not be the thing that determines
how often change event should fire.

Unfortunately, fixing the behavior outright caused too many existing
applications to fail. For this reason, Angular considers this fix a
breaking fix and has introduced a flag in `@ContentChildren` and
`@ViewChildren`, that controls the behavior.

```
export class QueryCompWithStrictChangeEmitParent {
  @ContentChildren('foo', {
    // This option is the new default with this change.
    emitDistinctChangesOnly: true,
  })
  foos!: QueryList<any>;
}
```
For backward compatibility before v12
`emitDistinctChangesOnlyDefaultValue` was set to `false. This change
changes the default to `true`.
@mhevery mhevery force-pushed the emitDistinctChangesOnlyDefaultValue branch from 28e117c to fa29891 Compare March 10, 2021 20:19
@mary-poppins
Copy link

You can preview fa29891 at https://pr41121-fa29891.ngbuilds.io/.

@mhevery
Copy link
Contributor Author

mhevery commented Mar 10, 2021

CARETAKER: cl/361617255 must land before this change

@mhevery mhevery added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Mar 10, 2021
@ngbot ngbot bot added the action: merge The PR is ready for merge by the caretaker label Mar 10, 2021
@mhevery mhevery removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Mar 10, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @mhevery 👍

Couple quick comments:

Thank you.

@AndrewKushnir AndrewKushnir added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Mar 10, 2021
@mhevery
Copy link
Contributor Author

mhevery commented Mar 10, 2021

presubmit

@pullapprove pullapprove bot requested a review from IgorMinar March 10, 2021 22:09
@mhevery mhevery removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Mar 10, 2021
@mary-poppins
Copy link

You can preview da5c248 at https://pr41121-da5c248.ngbuilds.io/.

@mhevery
Copy link
Contributor Author

mhevery commented Mar 11, 2021

@joost see a6ba19b

@mhevery mhevery removed the request for review from IgorMinar March 11, 2021 00:10
@pullapprove pullapprove bot requested a review from IgorMinar March 11, 2021 00:10
@mary-poppins
Copy link

You can preview a6ba19b at https://pr41121-a6ba19b.ngbuilds.io/.

@mhevery mhevery requested review from jelbourn and removed request for IgorMinar March 11, 2021 00:26
Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

Lgtm for public api change

Reviewed-for: public-api

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

Reviewed-for: public-api

@pullapprove pullapprove bot requested a review from IgorMinar March 12, 2021 16:01
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

Reviewed-for: docs-packaging-and-releasing

@mhevery mhevery removed the request for review from IgorMinar March 12, 2021 17:39
@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, 2021
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 aio: preview area: core Issues related to the framework runtime breaking changes cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants