Skip to content

Commit cd6c568

Browse files
committed
@imbcmdth fix potential triggerReady infinite loop
1 parent e225fbf commit cd6c568

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/js/component.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -785,13 +785,13 @@ class Component {
785785
this.setTimeout(function(){
786786
let readyQueue = this.readyQueue_;
787787

788+
// Reset Ready Queue
789+
this.readyQueue_ = [];
790+
788791
if (readyQueue && readyQueue.length > 0) {
789792
readyQueue.forEach(function(fn){
790793
fn.call(this);
791794
}, this);
792-
793-
// Reset Ready Queue
794-
this.readyQueue_ = [];
795795
}
796796

797797
// Allow for using event listeners also

test/unit/component.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,13 @@ test('should not retrigger a listener when the listener calls triggerReady', fun
419419
}
420420
};
421421

422-
var comp = new vjs.Component(getFakePlayer(), {});
422+
var comp = new Component(getFakePlayer(), {});
423423

424424
comp.ready(readyListener);
425425
comp.triggerReady();
426426

427+
this.clock.tick(100);
428+
427429
equal(timesCalled, 1, 'triggerReady from inside a ready handler does not result in an infinite loop');
428430
});
429431

0 commit comments

Comments
 (0)