Skip to content

Commit 79dd6a8

Browse files
alan-agius4AndrewKushnir
authored andcommittedJun 26, 2023
fix(platform-browser): wait until animation completion before destroying renderer (#50677)
Prior to this commit, the renderer destroy method was being called before the animation complete. This is problematic when using `REMOVE_STYLES_ON_COMPONENT_DESTROY` as it causes the styles to be removed too early. This commit, updates this destroy logic to be call the render destroy once the animations complete. This has been reported internally in: - http://b/271251353#comment12 - http://b/282004950#comment5 PR Close #50677
1 parent f9891c0 commit 79dd6a8

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
 

‎packages/animations/browser/src/render/animation_engine_next.ts

+4
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,8 @@ export class AnimationEngine {
113113
whenRenderingDone(): Promise<any> {
114114
return this._transitionEngine.whenRenderingDone();
115115
}
116+
117+
afterFlushAnimationsDone(cb: VoidFunction): void {
118+
this._transitionEngine.afterFlushAnimationsDone(cb);
119+
}
116120
}

‎packages/platform-browser/animations/src/animation_renderer.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,24 @@ export class AnimationRendererFactory implements RendererFactory2 {
138138
export class BaseAnimationRenderer implements Renderer2 {
139139
constructor(
140140
protected namespaceId: string, public delegate: Renderer2, public engine: AnimationEngine,
141-
private _onDestroy?: () => void) {
142-
this.destroyNode = this.delegate.destroyNode ? (n) => delegate.destroyNode!(n) : null;
143-
}
141+
private _onDestroy?: () => void) {}
144142

145143
get data() {
146144
return this.delegate.data;
147145
}
148146

149-
destroyNode: ((n: any) => void)|null;
147+
destroyNode(node: any): void {
148+
this.delegate.destroyNode?.(node);
149+
}
150150

151151
destroy(): void {
152152
this.engine.destroy(this.namespaceId, this.delegate);
153-
this.delegate.destroy();
153+
this.engine.afterFlushAnimationsDone(() => {
154+
// Call the renderer destroy method after the animations has finished as otherwise styles will
155+
// be removed too early which will cause an unstyled animation.
156+
this.delegate.destroy();
157+
});
158+
154159
this._onDestroy?.();
155160
}
156161

0 commit comments

Comments
 (0)
Please sign in to comment.