The Wayback Machine - https://web.archive.org/web/20220610043146/https://github.com/angular/angular/pull/45339
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(animations): apply default params when resolved value is null or undefined #45339

Closed
wants to merge 1 commit into from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Mar 13, 2022

The animations package supports adding default parameter values to an animation that will be used as a fallback if some parameters aren't defined. The problem is that they're applied using a spread expression which means that any own property of the animation parameters will override the defaults, even if it resolves to null or undefined. This can lead to obscure errors like "Cannot read property toString of undefined" for an animation that looks like {params: {foo: undefined}} with defaults {foo: 123}.

I ran into this issue while debugging some test failures on Material.

These changes address the issue by:

  1. Applying the defaults if the resolved value is null or undefined.
  2. Updating the validation function to use a null check instead of hasOwnProperty.

…undefined

The animations package supports adding default parameter values to an animation that will be used as a fallback if some parameters aren't defined. The problem is that they're applied using a spread expression which means that any own property of the animation parameters will override the defaults, even if it resolves to null or undefined. This can lead to obscure errors like "Cannot read property toString of undefined" for an animation that looks like `{params: {foo: undefined}}` with defaults `{foo: 123}`.

I ran into this issue while debugging some test failures on Material.

These changes address the issue by:
1. Applying the defaults if the resolved value is null or undefined.
2. Updating the validation function to use a null check instead of `hasOwnProperty`.
@crisbeto crisbeto force-pushed the animations-nullish-param branch from d50c14c to deeac84 Compare Mar 13, 2022
@@ -2394,6 +2394,42 @@ describe('animation tests', function() {
expect(hasStyle(element, 'height', '100px')).toBeTruthy();
}));

it('should apply default params when resolved animation value is null or undefined', () => {
Copy link
Member Author

@crisbeto crisbeto Mar 13, 2022

Choose a reason for hiding this comment

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

I was going back-and-forth between doing this versus throwing a proper error. I went with this, because it seemed weird for {foo: undefined, bar: 1} and {bar: 1} to behave differently.

This comment has been minimized.

@crisbeto crisbeto marked this pull request as ready for review Mar 13, 2022
@pullapprove pullapprove bot requested a review from jessicajaniuk Mar 13, 2022
@crisbeto crisbeto added comp: animations action: review target: patch labels Mar 13, 2022
@ngbot ngbot bot added this to the Backlog milestone Mar 13, 2022
@ngbot ngbot bot added this to the Backlog milestone Mar 13, 2022
@ngbot ngbot bot added this to the Backlog milestone Mar 13, 2022
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

LGTM 🍪

sorry for the delay on the review

@crisbeto crisbeto added action: merge and removed action: review labels Mar 17, 2022
@alxhub alxhub added target: minor and removed target: patch labels Mar 17, 2022
@alxhub
Copy link
Contributor

@alxhub alxhub commented Mar 17, 2022

@crisbeto FYI this doesn't merge cleanly to 13.3.x.

@alxhub
Copy link
Contributor

@alxhub alxhub commented Mar 17, 2022

This PR was merged into the repository by commit 2a75754.

PiyushAgrawal1243 pushed a commit to PiyushAgrawal1243/angular that referenced this issue Mar 30, 2022
…undefined (angular#45339)

The animations package supports adding default parameter values to an animation that will be used as a fallback if some parameters aren't defined. The problem is that they're applied using a spread expression which means that any own property of the animation parameters will override the defaults, even if it resolves to null or undefined. This can lead to obscure errors like "Cannot read property toString of undefined" for an animation that looks like `{params: {foo: undefined}}` with defaults `{foo: 123}`.

I ran into this issue while debugging some test failures on Material.

These changes address the issue by:
1. Applying the defaults if the resolved value is null or undefined.
2. Updating the validation function to use a null check instead of `hasOwnProperty`.

PR Close angular#45339
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this issue Apr 8, 2022
…undefined (angular#45339)

The animations package supports adding default parameter values to an animation that will be used as a fallback if some parameters aren't defined. The problem is that they're applied using a spread expression which means that any own property of the animation parameters will override the defaults, even if it resolves to null or undefined. This can lead to obscure errors like "Cannot read property toString of undefined" for an animation that looks like `{params: {foo: undefined}}` with defaults `{foo: 123}`.

I ran into this issue while debugging some test failures on Material.

These changes address the issue by:
1. Applying the defaults if the resolved value is null or undefined.
2. Updating the validation function to use a null check instead of `hasOwnProperty`.

PR Close angular#45339
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Apr 17, 2022

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 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge comp: animations target: minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants