From d2a86872a9c4dc17aad8068746cf55e880b7968c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Thu, 10 May 2018 15:57:58 -0700 Subject: [PATCH] fix(animations): do not throw errors when a destroyed component is animated (#23836) PR Close #23836 --- .../browser/src/render/transition_animation_engine.ts | 7 +++++-- .../test/render/transition_animation_engine_spec.ts | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/animations/browser/src/render/transition_animation_engine.ts b/packages/animations/browser/src/render/transition_animation_engine.ts index 192c747e87..205f6ecbba 100644 --- a/packages/animations/browser/src/render/transition_animation_engine.ts +++ b/packages/animations/browser/src/render/transition_animation_engine.ts @@ -649,8 +649,11 @@ export class TransitionAnimationEngine { trigger(namespaceId: string, element: any, name: string, value: any): boolean { if (isElementNode(element)) { - this._fetchNamespace(namespaceId).trigger(element, name, value); - return true; + const ns = this._fetchNamespace(namespaceId); + if (ns) { + ns.trigger(element, name, value); + return true; + } } return false; } diff --git a/packages/animations/browser/test/render/transition_animation_engine_spec.ts b/packages/animations/browser/test/render/transition_animation_engine_spec.ts index 314b262780..5a122e9bd5 100644 --- a/packages/animations/browser/test/render/transition_animation_engine_spec.ts +++ b/packages/animations/browser/test/render/transition_animation_engine_spec.ts @@ -616,6 +616,13 @@ const DEFAULT_NAMESPACE_ID = 'id'; expect(element.contains(child1)).toBe(true); expect(element.contains(child2)).toBe(true); }); + + it('should not throw an error if a missing namespace is used', () => { + const engine = makeEngine(); + const ID = 'foo'; + const TRIGGER = 'fooTrigger'; + expect(() => { engine.trigger(ID, element, TRIGGER, 'something'); }).not.toThrow(); + }); }); }); })();