Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBjs Core: bugfix - accessing array instead of adUnit #10567

Closed
wants to merge 3 commits into from

Conversation

karimMourra
Copy link
Collaborator

Type of change

  • Bugfix

  • Does this change affect user-facing APIs or examples documented on http://prebid.org?

  • Other

Description of change

pbjsInstance.adUnits.filter returns an array yet the code was expecting an actual ad unit. This fix uses auctionManager.index.getAdUnit to get the ad unit and adds a check for the divId before attempting to render the ad.
Integration example has been updated.

Other information

fixes issue #10505

@karimMourra karimMourra requested a review from dgirardi October 3, 2023 19:01
@ChrisHuie ChrisHuie changed the title Core: Bugfix - accessing array instead of adUnit PBjs Core: bugfix - accessing array instead of adUnit Oct 4, 2023
src/prebid.js Outdated
@@ -525,11 +525,11 @@ pbjsInstance.renderAd = hook('async', function (doc, id, options) {

// video module
if (FEATURES.VIDEO) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this short-circuit if the bid is not a video bid (bid.mediaType === 'video')? to avoid looking up the adUnit - since in 99% of cases this will be used for display and the lookup takes some CPU time.

Also - could you add some tests - verifying that videoModule.renderBid in invoked when and how you expect it to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgirardi addressed!

@patmmccann patmmccann linked an issue Oct 5, 2023 that may be closed by this pull request
@patmmccann patmmccann requested a review from dgirardi November 14, 2023 18:56
Comment on lines +38 to +44
if (FEATURES.VIDEO && bid.mediaType === 'video') {
// TODO: could the video module implement this as a custom renderer, rather than a special case in here?
const adUnit = bid && auctionManager.index.getAdUnit(bid);
const videoModule = getGlobal().videoModule;
if (adUnit?.video && videoModule) {
videoModule.renderBid(adUnit.video.divId, bid);
const divId = adUnit && adUnit.video && adUnit.video.divId;
if (divId && videoModule) {
videoModule.renderBid(divId, bid);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgirardi i ported the changes over to direct.js ; open to creating a custom renderer but not sure what you mean by that . Is it an existing pattern ?

@patmmccann
Copy link
Collaborator

@karimMourra assume you see these test errors?

  1. should log an error when ad not found
    Unit: Prebid Module renderAd
    AssertionError: expected error was logged: expected false to be truthy
    at Context. (/tmp/_karma_webpack_785343/commons.js:483477:14)

  2. should render in the Video Module when mediaType is video and the AdUnit includes a video config
    Unit: Prebid Module renderAd
    AssertionError: videoModule.renderBid should be called when adUnit is configured for Video Module: expected false to be truthy
    at Context. (/tmp/_karma_webpack_785343/commons.js:483613:16)

@patmmccann patmmccann assigned karimMourra and unassigned dgirardi Jun 18, 2024
@karimMourra
Copy link
Collaborator Author

fixed in #10819

@karimMourra karimMourra closed this Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in renderAd for video
4 participants