prebid / Prebid.js

Setup and manage header bidding advertising partners without writing code or confusing line items. Prebid.js is open source and free.
http://prebid.org
Apache License 2.0
1.26k stars 2.02k forks source link

Functions in que are processed before functions in cmd #11906

Open bozghiyy opened 6 days ago

bozghiyy commented 6 days ago

Type of issue

unexpected behavior / questions

Description

The function queued using pbjs.que are processed before functions queued with pbjs.cmd before prebid library is loaded

Steps to reproduce

Queue any function (even a console log) with pbjs.que and pbjs.cmd and observe the execution order.

Test page

https://jsfiddle.net/bozghiyy/2ndgv504/

Expected results

The function to execute in the order that they are queued.

Actual results

Function queued with pbjs.que are processed first until prebid library is loaded and all the queues are processed. After that functions are processed in the order that are queued. image

Platform details

All. Independent of platform.

Other information

Probably is due https://github.com/prebid/Prebid.js/blob/master/src/prebid.js#L981-L982, processing first que and then cmd.

It can cause issues when trying to run some prebid commands from a 3rd party script, the order or execution is unknown since is a race condition between prebid library and the 3rd party script. If you are aware how they work, it can be mitigated.

I do not know if I would consider this a bug and if anything needs to be "fixed", I wanted just to know an opinion if this is the intended way. My questions would be:

patmmccann commented 6 days ago

As an aside, the chromium team is recommending async processing of these

https://github.com/prebid/Prebid.js/issues/10062#issuecomment-1798592536

dgirardi commented 6 days ago

It can cause issues when trying to run some prebid commands from a 3rd party script, the order or execution is unknown since is a race condition between prebid library and the 3rd party script. If you are aware how they work, it can be mitigated.

What scenario do you have in mind? I can't think of any way to be sure of how your commands will line up if you're setting them up from a 3rd party script - even if you had just one queue.

We will always have cross-compatibility for que and cmd? (maybe one should be removed in a major release)

I agree they are redundant - but I am not sure about getting rid of one as it'd be asking users to potentially do a lot of work for very little gain.

If there is a priority in execution process queue, shouldn't cmd be first? (alphabetically and is the preferred method)

Reasonable, but again at this point it's more likely to create problems than to be an improvement.