From f88fba020b32c2b6aa187d92d8eee90e4c2a68b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Wed, 31 Jan 2018 15:11:39 -0800 Subject: [PATCH] fix(animations): avoid animation insertions during router back/refresh (#21977) Closes #19712 PR Close #21977 --- .../browser/src/render/transition_animation_engine.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/animations/browser/src/render/transition_animation_engine.ts b/packages/animations/browser/src/render/transition_animation_engine.ts index d41d4f2cd7..cb8741b37e 100644 --- a/packages/animations/browser/src/render/transition_animation_engine.ts +++ b/packages/animations/browser/src/render/transition_animation_engine.ts @@ -666,7 +666,16 @@ export class TransitionAnimationEngine { // code does not contain any animation code in it, but it is // just being called so that the node is marked as being inserted if (namespaceId) { - this._fetchNamespace(namespaceId).insertNode(element, parent); + const ns = this._fetchNamespace(namespaceId); + // This if-statement is a workaround for router issue #21947. + // The router sometimes hits a race condition where while a route + // is being instantiated a new navigation arrives, triggering leave + // animation of DOM that has not been fully initialized, until this + // is resolved, we need to handle the scenario when DOM is not in a + // consistent state during the animation. + if (ns) { + ns.insertNode(element, parent); + } } // only *directives and host elements are inserted before