Skip to content

Commit 42e1c66

Browse files
jeremiegiraultmarc_tappx
authored and
marc_tappx
committed
PBJS Core: call custom render func after loadscript if provided (prebid#6422)
1 parent ac5c107 commit 42e1c66

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Renderer.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,22 @@ export function Renderer(options) {
3939

4040
// use a function, not an arrow, in order to be able to pass "arguments" through
4141
this.render = function () {
42+
const renderArgs = arguments
43+
const runRender = () => {
44+
if (this._render) {
45+
this._render.apply(this, renderArgs)
46+
} else {
47+
utils.logWarn(`No render function was provided, please use .setRender on the renderer`);
48+
}
49+
}
50+
4251
if (!isRendererPreferredFromAdUnit(adUnitCode)) {
4352
// we expect to load a renderer url once only so cache the request to load script
53+
this.cmd.unshift(runRender) // should render run first ?
4454
loadExternalScript(url, moduleCode, this.callback);
4555
} else {
4656
utils.logWarn(`External Js not loaded by Renderer since renderer url and callback is already defined on adUnit ${adUnitCode}`);
47-
}
48-
49-
if (this._render) {
50-
this._render.apply(this, arguments) // _render is expected to use push as appropriate
51-
} else {
52-
utils.logWarn(`No render function was provided, please use .setRender on the renderer`);
57+
runRender()
5358
}
5459
}.bind(this) // bind the function to this object to avoid 'this' errors
5560
}

0 commit comments

Comments
 (0)