Skip to content

Commit 3bff5ba

Browse files
authored
Merge pull request #169 from SpringRoll/feature/preload-behaviour
Preload Check
2 parents 3444a1c + 981936d commit 3bff5ba

File tree

7 files changed

+24
-4
lines changed

7 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.5.0] - unreleased
9+
10+
### Added
11+
12+
- Added a check to make sure plugin preloads are finished before opening up the application to avoid race conditions.
13+
814
## [2.4.6] - unreleased
915

1016
### Fixed

dist/SpringRoll-Container-umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/SpringRoll-Container-umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Container.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class Container extends PluginManager {
2828
super({ plugins });
2929

3030
this.iframe = iframeOrSelector instanceof HTMLIFrameElement ? iframeOrSelector : document.querySelector(iframeOrSelector);
31+
this.iframe.style.backgroundColor = 'black';
3132

3233
if (null === this.iframe) {
3334
throw new Error('No iframe was found with the provided selector');
@@ -141,6 +142,15 @@ export class Container extends PluginManager {
141142
* @memberof Container
142143
*/
143144
_internalOpen(userPath, { singlePlay = false, playOptions = null } = {}) {
145+
// If plugin preloads are still going wait for them to finish before opening the Application
146+
if (this.preloading) {
147+
this.client.on('preloadsFinished', () => {
148+
this._internalOpen(userPath, { singlePlay, playOptions });
149+
});
150+
151+
return;
152+
}
153+
144154
const options = { singlePlay, playOptions };
145155
this.reset();
146156

src/PluginManager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class PluginManager {
1515
*/
1616
constructor({ plugins = [] }) {
1717
this.client = new Bellhop();
18+
this.preloading = true;
1819
// @ts-ignore
1920
this.client.hidden = this.client.receive.bind(this.client);
2021
// @ts-ignore
@@ -57,6 +58,9 @@ export default class PluginManager {
5758
plugin => plugin.preloadFailed !== true
5859
);
5960

61+
this.preloading = false;
62+
this.client.trigger('preloadsFinished');
63+
6064
//init
6165
this.plugins.forEach(plugin => {
6266
if (!plugin.init) {

0 commit comments

Comments
 (0)