Sitelet https://github.com/angular/angular/pull/64592/files
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/core/src/render3/instructions/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function ɵɵanimateEnter(value: string | Function): typeof ɵɵanimateEn
}

const tNode = getCurrentTNode()!;

cancelLeavingNodes(tNode, lView);

addAnimationToLView(getLViewEnterAnimations(lView), tNode, () =>
Expand Down Expand Up @@ -196,7 +195,6 @@ export function ɵɵanimateEnterListener(value: AnimationFunction): typeof ɵɵa
return ɵɵanimateEnterListener;
}
const tNode = getCurrentTNode()!;

cancelLeavingNodes(tNode, lView);

addAnimationToLView(getLViewEnterAnimations(lView), tNode, () =>
Expand Down Expand Up @@ -251,6 +249,7 @@ export function ɵɵanimateLeave(value: string | Function): typeof ɵɵanimateLe
}

const tNode = getCurrentTNode()!;
cancelLeavingNodes(tNode, lView);

addAnimationToLView(getLViewLeaveAnimations(lView), tNode, () =>
runLeaveAnimations(lView, tNode, value),
Expand Down Expand Up @@ -383,6 +382,8 @@ export function ɵɵanimateLeaveListener(value: AnimationFunction): typeof ɵɵa

const lView = getLView();
const tNode = getCurrentTNode()!;
cancelLeavingNodes(tNode, lView);

allLeavingAnimations.add(lView);

addAnimationToLView(getLViewLeaveAnimations(lView), tNode, () =>
Expand Down
51 changes: 51 additions & 0 deletions packages/core/test/acceptance/animation_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
AfterViewInit,
AnimationCallbackEvent,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
computed,
Directive,
ElementRef,
inject,
NgModule,
OnDestroy,
provideZonelessChangeDetection,
Expand Down Expand Up @@ -1627,6 +1629,55 @@ describe('Animation', () => {
expect(paragraphs.length).toBe(1);
}));

it('should reset leave animation and not duplicate node when toggled programmatically very quickly', fakeAsync(() => {
const animateStyles = `
.fade {
animation: fade-out 500ms;
}
@keyframes fade-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
`;

@Component({
selector: 'test-cmp',
styles: animateStyles,
template: '<div>@if (show()) {<p animate.leave="fade">I should fade</p>}</div>',
encapsulation: ViewEncapsulation.None,
})
class TestComponent {
show = signal(false);
cdr = inject(ChangeDetectorRef);

toggle() {
this.show.update((s) => !s);
setTimeout(() => {
this.show.update((s) => !s);
this.cdr.detectChanges();

setTimeout(() => {
this.show.update((s) => !s);
this.cdr.detectChanges();
});
});
}
}
TestBed.configureTestingModule({animationsEnabled: true});

const fixture = TestBed.createComponent(TestComponent);
const cmp = fixture.componentInstance;
cmp.toggle();
fixture.detectChanges();
tickAnimationFrames(1);
const paragraphs = fixture.debugElement.queryAll(By.css('p'));
expect(paragraphs.length).toBe(1);
}));

it('should always run animations for `@for` loops when adding and removing quickly', fakeAsync(() => {
const animateStyles = `
.slide-in {
Expand Down