-
Notifications
You must be signed in to change notification settings - Fork 27.2k
fix(core): deferred blocks not removing content immediately when animations are enabled #51971
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
|
|
||
| import {ɵPLATFORM_BROWSER_ID as PLATFORM_BROWSER_ID} from '@angular/common'; | ||
| import {ɵsetEnabledBlockTypes as setEnabledBlockTypes} from '@angular/compiler/src/jit_compiler_facade'; | ||
| import {Component, Input, PLATFORM_ID, QueryList, Type, ViewChildren, ɵDEFER_BLOCK_DEPENDENCY_INTERCEPTOR} from '@angular/core'; | ||
| import {Component, Input, NgZone, PLATFORM_ID, QueryList, Type, ViewChildren, ɵDEFER_BLOCK_DEPENDENCY_INTERCEPTOR} from '@angular/core'; | ||
| import {getComponentDef} from '@angular/core/src/render3/definition'; | ||
| import {DeferBlockBehavior, fakeAsync, flush, TestBed} from '@angular/core/testing'; | ||
|
|
||
|
|
@@ -1227,6 +1227,7 @@ describe('@defer', () => { | |
| template: 'Primary block content.', | ||
| }) | ||
| class NestedCmp { | ||
| @Input() block!: string; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unrelated, I just noticed that it was logging a warning. |
||
| } | ||
|
|
||
| @Component({ | ||
|
|
@@ -1403,6 +1404,7 @@ describe('@defer', () => { | |
| template: 'Primary block content.', | ||
| }) | ||
| class NestedCmp { | ||
| @Input() block!: string; | ||
| } | ||
|
|
||
| @Component({ | ||
|
|
@@ -1956,6 +1958,32 @@ describe('@defer', () => { | |
| expect(spy).toHaveBeenCalledWith('keydown', jasmine.any(Function), jasmine.any(Object)); | ||
| })); | ||
|
|
||
| it('should bind the trigger events inside the NgZone', fakeAsync(() => { | ||
| @Component({ | ||
| standalone: true, | ||
| template: ` | ||
| @defer (on interaction(trigger)) { | ||
| Main content | ||
| } | ||
|
|
||
| <button #trigger></button> | ||
| ` | ||
| }) | ||
| class MyCmp { | ||
| } | ||
|
|
||
| const eventsInZone: Record<string, boolean> = {}; | ||
| const fixture = TestBed.createComponent(MyCmp); | ||
| const button = fixture.nativeElement.querySelector('button'); | ||
|
|
||
| spyOn(button, 'addEventListener').and.callFake((name: string) => { | ||
| eventsInZone[name] = NgZone.isInAngularZone(); | ||
| }); | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(eventsInZone).toEqual({click: true, keydown: true}); | ||
| })); | ||
|
|
||
| it('should prefetch resources on interaction', fakeAsync(() => { | ||
| @Component({ | ||
| standalone: true, | ||
|
|
@@ -2254,6 +2282,32 @@ describe('@defer', () => { | |
| expect(spy).toHaveBeenCalledWith('mouseenter', jasmine.any(Function), jasmine.any(Object)); | ||
| })); | ||
|
|
||
| it('should bind the trigger events inside the NgZone', fakeAsync(() => { | ||
| @Component({ | ||
| standalone: true, | ||
| template: ` | ||
| @defer (on hover(trigger)) { | ||
| Main content | ||
| } | ||
|
|
||
| <button #trigger></button> | ||
| ` | ||
| }) | ||
| class MyCmp { | ||
| } | ||
|
|
||
| const eventsInZone: Record<string, boolean> = {}; | ||
| const fixture = TestBed.createComponent(MyCmp); | ||
| const button = fixture.nativeElement.querySelector('button'); | ||
|
|
||
| spyOn(button, 'addEventListener').and.callFake((name: string) => { | ||
| eventsInZone[name] = NgZone.isInAngularZone(); | ||
| }); | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(eventsInZone).toEqual({mouseenter: true}); | ||
| })); | ||
|
|
||
| it('should prefetch resources on hover', fakeAsync(() => { | ||
| // Domino doesn't support creating custom events so we have to skip this test. | ||
| if (!isBrowser) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I was having a hard time capturing this behavior in a unit test, because the testing APIs would trigger change detection which would flush the animations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment, I haven't seen it while leaving a review comment (#51971 (review)). May be we can have a test to make sure that we run event handlers inside NgZone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't know if we can observe the internal event handlers without introducing another DI token. I ended up adding a dev mode assertion that it's in the
NgZonewhich should give us the same result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the assertion isn't super reliable since Zone.js doesn't seem to patch
addEventListenerin the same way in Node and in the browser so we were getting different test results. I reworked it to spy onaddEventListenerand check that it's called within the zone instead.