Skip to content

Commit 80075af

Browse files
matskomhevery
authored andcommitted
fix(animations): only process element nodes through the animation engine (#15268)
Closes #15267 Closes #15268 PR Close #15268
1 parent bcc29ff commit 80075af

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

Diff for: packages/animations/browser/src/render/dom_animation_engine.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ export class DomAnimationEngine {
6767
}
6868

6969
onInsert(element: any, domFn: () => any): void {
70-
this._flaggedInserts.add(element);
70+
if (element['nodeType'] == 1) {
71+
this._flaggedInserts.add(element);
72+
}
7173
domFn();
7274
}
7375

7476
onRemove(element: any, domFn: () => any): void {
77+
if (element['nodeType'] != 1) {
78+
domFn();
79+
return;
80+
}
81+
7582
let lookupRef = this._elementTriggerStates.get(element);
7683
if (lookupRef) {
7784
const possibleTriggers = Object.keys(lookupRef);

Diff for: packages/animations/browser/src/render/noop_animation_engine.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ export class NoopAnimationEngine extends AnimationEngine {
5454

5555
onRemove(element: any, domFn: () => any): void {
5656
domFn();
57-
this._flaggedRemovals.add(element);
57+
if (element['nodeType'] == 1) {
58+
this._flaggedRemovals.add(element);
59+
}
5860
}
5961

6062
setProperty(element: any, property: string, value: any): void {

Diff for: packages/animations/browser/test/engine/dom_animation_engine_spec.ts

+23
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,29 @@ export function main() {
328328
});
329329
});
330330

331+
describe('removals / insertions', () => {
332+
it('should allow text nodes to be removed through the engine', () => {
333+
const engine = makeEngine();
334+
const node = document.createTextNode('hello');
335+
element.appendChild(node);
336+
337+
let called = false;
338+
engine.onRemove(node, () => called = true);
339+
340+
expect(called).toBeTruthy();
341+
});
342+
343+
it('should allow text nodes to be inserted through the engine', () => {
344+
const engine = makeEngine();
345+
const node = document.createTextNode('hello');
346+
347+
let called = false;
348+
engine.onInsert(node, () => called = true);
349+
350+
expect(called).toBeTruthy();
351+
});
352+
});
353+
331354
describe('transition operations', () => {
332355
it('should persist the styles on the element as actual styles once the animation is complete',
333356
() => {

Diff for: packages/platform-browser/animations/test/noop_animation_engine_spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export function main() {
2020
() => {
2121
const engine = new NoopAnimationEngine();
2222

23-
const elm1 = {};
24-
const elm2 = {};
23+
const elm1 = {nodeType: 1};
24+
const elm2 = {nodeType: 1};
2525
engine.onRemove(elm1, capture('1'));
2626
engine.onRemove(elm2, capture('2'));
2727

@@ -158,7 +158,7 @@ export function main() {
158158

159159
it('should fire a removal listener even if the listener is deregistered prior to flush', () => {
160160
const engine = new NoopAnimationEngine();
161-
const elm = {};
161+
const elm = {nodeType: 1};
162162

163163
const fn = engine.listen(elm, 'trig', 'start', capture('removal listener'));
164164
fn();

0 commit comments

Comments
 (0)