Skip to content

Commit 684843e

Browse files
GPTUtils: Prevent caching empty slot info in gptUtils and add empty info test cases (#13706)
1 parent a5f77e8 commit 684843e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

libraries/gptUtils/gptUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CLIENT_SECTIONS } from '../../src/fpd/oneClient.js';
2-
import {compareCodeAndSlot, deepAccess, isGptPubadsDefined, uniques} from '../../src/utils.js';
2+
import {compareCodeAndSlot, deepAccess, isGptPubadsDefined, uniques, isEmpty} from '../../src/utils.js';
33

44
const slotInfoCache = new Map();
55

@@ -55,7 +55,7 @@ export function getGptSlotInfoForAdUnitCode(adUnitCode) {
5555
divId: matchingSlot.getSlotElementId()
5656
};
5757
}
58-
slotInfoCache.set(adUnitCode, info);
58+
!isEmpty(info) && slotInfoCache.set(adUnitCode, info);
5959
return info;
6060
}
6161

test/spec/libraries/gptUtils_spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ describe('gptUtils', () => {
1515
const second = gptUtils.getGptSlotInfoForAdUnitCode('code');
1616
expect(first).to.deep.equal({ gptSlot: 'code', divId: 'div-id' });
1717
expect(second).to.deep.equal(first);
18+
const third = gptUtils.getGptSlotInfoForAdUnitCode('code1'); // not found
19+
expect(third).to.deep.equal({});
1820
});
1921
});

0 commit comments

Comments
 (0)