Skip to content

Commit 0b984ce

Browse files
committed
include renderAds prop in portals component and only convert to placeholders if renderAds is true
1 parent 4991f47 commit 0b984ce

File tree

8 files changed

+21
-16
lines changed

8 files changed

+21
-16
lines changed

dotcom-rendering/src/components/AdPortals.importable.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ const debounceUpdateAds = libDebounce(updateAds, 100, { leading: true });
104104

105105
export const AdPortals = ({
106106
rightAlignFrom = 'desktop',
107+
renderAds,
107108
}: {
108109
// In most cases, we want to try to display ads in the right column from desktop upwards.
109110
// For blogs, we want right aligned from wide upwards.
110111
rightAlignFrom?: Breakpoint;
112+
renderAds?: boolean;
111113
}) => {
112114
// Server-rendered placeholder elements for inline ad slots to be inserted into (below desktop breakpoint)
113115
const [adPlaceholders, setAdPlaceholders] = useState<Element[]>([]);
@@ -137,7 +139,7 @@ export const AdPortals = ({
137139
void getUserClient()
138140
.isPremium()
139141
.then((isPremium) => {
140-
if (!isPremium) {
142+
if (!isPremium && renderAds) {
141143
setAdPlaceholders(
142144
Array.from(
143145
document.getElementsByClassName(adPlaceholderClass),
@@ -151,7 +153,7 @@ export const AdPortals = ({
151153
}
152154
})
153155
.catch(() => console.error('Error setting up ads'));
154-
}, []);
156+
}, [renderAds]);
155157

156158
/**
157159
* Insert Ads

dotcom-rendering/src/layouts/CommentLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ export const CommentLayout = (props: WebProps | AppsProps) => {
347347
)}
348348

349349
<main data-layout="CommentLayout">
350-
{renderAds && isApps && (
350+
{isApps && (
351351
<Island priority="critical">
352-
<AdPortals />
352+
<AdPortals renderAds={renderAds} />
353353
</Island>
354354
)}
355355
<Section

dotcom-rendering/src/layouts/ImmersiveLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ export const ImmersiveLayout = (props: WebProps | AppProps) => {
437437
)}
438438

439439
<main data-layout="ImmersiveLayout">
440-
{renderAds && isApps && (
440+
{isApps && (
441441
<Island priority="critical">
442-
<AdPortals />
442+
<AdPortals renderAds={renderAds} />
443443
</Island>
444444
)}
445445
<Section

dotcom-rendering/src/layouts/InteractiveLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ export const InteractiveLayout = (props: WebProps | AppsProps) => {
324324
</>
325325
)}
326326
<main data-layout="InteractiveLayout">
327-
{renderAds && isApps && (
327+
{isApps && (
328328
<Island priority="critical">
329-
<AdPortals />
329+
<AdPortals renderAds={renderAds} />
330330
</Island>
331331
)}
332332
<Section

dotcom-rendering/src/layouts/LiveLayout.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,12 @@ export const LiveLayout = (props: WebProps | AppsProps) => {
361361
</Section>
362362
</Hide>
363363
)}
364-
{renderAds && isApps && (
364+
{isApps && (
365365
<Island priority="critical">
366-
<AdPortals rightAlignFrom="wide" />
366+
<AdPortals
367+
rightAlignFrom="wide"
368+
renderAds={renderAds}
369+
/>
367370
</Island>
368371
)}
369372
{footballMatchUrl ? (

dotcom-rendering/src/layouts/PictureLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ export const PictureLayout = (props: WebProps | AppsProps) => {
330330
lang={decideLanguage(article.lang)}
331331
dir={decideLanguageDirection(article.isRightToLeftLang)}
332332
>
333-
{renderAds && isApps && (
333+
{isApps && (
334334
<Island priority="critical">
335-
<AdPortals />
335+
<AdPortals renderAds={renderAds} />
336336
</Island>
337337
)}
338338
<Section

dotcom-rendering/src/layouts/ShowcaseLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ export const ShowcaseLayout = (props: WebProps | AppsProps) => {
371371
lang={decideLanguage(article.lang)}
372372
dir={decideLanguageDirection(article.isRightToLeftLang)}
373373
>
374-
{renderAds && isApps && (
374+
{isApps && (
375375
<Island priority="critical">
376-
<AdPortals />
376+
<AdPortals renderAds={renderAds} />
377377
</Island>
378378
)}
379379
<Section

dotcom-rendering/src/layouts/StandardLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ export const StandardLayout = (props: WebProps | AppProps) => {
453453
)}
454454

455455
<main data-layout="StandardLayout">
456-
{renderAds && isApps && (
456+
{isApps && (
457457
<Island priority="critical">
458-
<AdPortals />
458+
<AdPortals renderAds={renderAds} />
459459
</Island>
460460
)}
461461
<Section

0 commit comments

Comments
 (0)