Skip to content
This repository was archived by the owner on Sep 28, 2025. It is now read-only.

Commit 4e73425

Browse files
Merge pull request #108 from clappr/feature/fix-leaks
Fix leaks
2 parents d6c99a4 + c40fc5a commit 4e73425

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

src/components/core/core.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default class Core extends UIObject {
115115
this.playerError = new PlayerError(options, this)
116116
this.configureDomRecycler()
117117
this.firstResize = true
118+
this.styleRendered = false
118119
this.plugins = []
119120
this.containers = []
120121
//FIXME fullscreen api sucks
@@ -367,16 +368,24 @@ export default class Core extends UIObject {
367368
}
368369

369370
appendToParent() {
370-
const style = Styler.getStyleFor(CoreStyle.toString(), { baseUrl: this.options.baseUrl })
371-
const resetStyle = Styler.getStyleFor(ResetStyle.toString(), { baseUrl: this.options.baseUrl })
372-
this.$el.append(style[0])
373-
this.options.includeResetStyle && this.$el.append(resetStyle[0])
374-
375371
const hasCoreParent = this.$el.parent() && this.$el.parent().length
376372
!hasCoreParent && this.$el.appendTo(this.options.parentElement)
377373
}
378374

375+
appendStyles() {
376+
if (this.styleRendered) return
377+
378+
const style = Styler.getStyleFor(CoreStyle.toString(), { baseUrl: this.options.baseUrl })
379+
this.$el.append(style[0])
380+
if (this.options.includeResetStyle) {
381+
const resetStyle = Styler.getStyleFor(ResetStyle.toString(), { baseUrl: this.options.baseUrl })
382+
this.$el.append(resetStyle[0])
383+
}
384+
this.styleRendered = true
385+
}
386+
379387
render() {
388+
this.appendStyles()
380389
this.options.width = this.options.width || this.$el.width()
381390
this.options.height = this.options.height || this.$el.height()
382391
const size = { width: this.options.width, height: this.options.height }

src/components/core/core.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,38 @@ describe('Core', function() {
285285
})
286286
})
287287
})
288+
289+
describe('when rendering', () => {
290+
beforeEach(() => {
291+
this.core = new Core({})
292+
})
293+
294+
test('append default style element', () => {
295+
this.core.render()
296+
297+
expect(this.core.el.children.length).toEqual(1)
298+
expect(this.core.el.children[0].tagName).toEqual('STYLE')
299+
})
300+
301+
test('append default and reset style elements with includeResetStyle set', () => {
302+
const newOptions = {
303+
includeResetStyle: true,
304+
}
305+
this.core.configure(newOptions)
306+
307+
this.core.render()
308+
309+
expect(this.core.el.children.length).toEqual(2)
310+
expect(this.core.el.children[0].tagName).toEqual('STYLE')
311+
expect(this.core.el.children[1].tagName).toEqual('STYLE')
312+
})
313+
314+
test('does append style elements twice', () => {
315+
this.core.render()
316+
this.core.render()
317+
318+
expect(this.core.el.children.length).toEqual(1)
319+
expect(this.core.el.children[0].tagName).toEqual('STYLE')
320+
})
321+
})
288322
})

src/components/loader/loader.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('Loader', () => {
1818
describe('checkVersionSupport function', () => {
1919
let corePlugin, containerPlugin
2020
beforeEach(() => {
21-
corePlugin = CorePlugin.extend({ name: 'core-plugin', supportedVersion: { min: '0.4.0' } })
21+
corePlugin = CorePlugin.extend({ name: 'core-plugin', supportedVersion: { min: '0.5.0' } })
2222
containerPlugin = ContainerPlugin.extend({ name: 'container-plugin', supportedVersion: { min: '0.4.0', max: '9.9.9' } })
2323
})
2424

src/playbacks/html5_video/html5_video.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ export default class HTML5Video extends Playback {
498498
destroy() {
499499
this._destroyed = true
500500
this.handleTextTrackChange && this.el.textTracks.removeEventListener('change', this.handleTextTrackChange)
501+
this.$el.off('contextmenu')
501502
super.destroy()
502503
this.el.removeAttribute('src')
503504
this.el.load() // load with no src to stop loading of the previous source and avoid leaks

0 commit comments

Comments
 (0)