Skip to content

Commit a56e269

Browse files
authored
Merge pull request #15466 from guardian/doml/slim-homepage-abtest-safeguard
Slim homepage AB test: Hide Deeply Read if not enough space
2 parents 81bf039 + 0d791d2 commit a56e269

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

dotcom-rendering/src/components/FrontPage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { SetABTests } from './SetABTests.importable';
2121
import { SetAdTargeting } from './SetAdTargeting.importable';
2222
import { ShowHideContainers } from './ShowHideContainers.importable';
2323
import { SkipTo } from './SkipTo';
24+
import { SlimHomepageAbTest } from './SlimHomepageAbTest.importable';
2425

2526
type Props = {
2627
front: Front;
@@ -97,6 +98,9 @@ export const FrontPage = ({ front, NAV }: Props) => {
9798
<Island priority="feature" defer={{ until: 'idle' }}>
9899
<ReaderRevenueDev shouldHideReaderRevenue={false} />
99100
</Island>
101+
<Island priority="enhancement" defer={{ until: 'idle' }}>
102+
<SlimHomepageAbTest />
103+
</Island>
100104
{isGoogleOneTapEnabled(
101105
front.config.abTests,
102106
front.config.switches,

dotcom-rendering/src/components/MostPopularFrontRight.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ type Props = {
8989
export const MostPopularFrontRight = ({ heading, trails }: Props) => {
9090
if (trails.length === 0) return null;
9191

92+
const containerId = `${heading
93+
.toLowerCase()
94+
.replace(' ', '-')}-front-right-container`;
95+
9296
return (
9397
<section
98+
id={containerId}
9499
data-component="most-popular-front-right"
95100
css={[
96101
containerStyles,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useEffect } from 'react';
2+
3+
/**
4+
* If the "Deeply read" container is taller than the combined height of the "Features" and "More features"
5+
* containers, hide the "Deeply read" container to prevent this absolute positioned component from
6+
* overlapping the container or advert below it.
7+
*
8+
* The intention is that for the duration of the AB test there will always be enough content in these
9+
* two containers to ensure that there is enough room for the "Deeply read" container, but this is added
10+
* as a safety net: it is better to remove the content than to leave it overlapping other content.
11+
*
12+
* @returns {JSX.Element} - A React fragment (renders nothing to the DOM directly).
13+
*/
14+
export const SlimHomepageAbTest = () => {
15+
useEffect(() => {
16+
const featuresContainer = document.getElementById('features');
17+
const moreFeaturesContainer = document.getElementById('more-features');
18+
const deeplyReadFrontRightContainer = document.getElementById(
19+
'deeply-read-front-right-container',
20+
);
21+
22+
if (
23+
deeplyReadFrontRightContainer &&
24+
featuresContainer &&
25+
moreFeaturesContainer
26+
) {
27+
const deeplyReadHeight =
28+
deeplyReadFrontRightContainer.getBoundingClientRect().height;
29+
const featuresHeight =
30+
featuresContainer.getBoundingClientRect().height;
31+
const moreFeaturesHeight =
32+
moreFeaturesContainer.getBoundingClientRect().height;
33+
34+
if (deeplyReadHeight > featuresHeight + moreFeaturesHeight) {
35+
deeplyReadFrontRightContainer.style.display = 'none';
36+
}
37+
}
38+
}, []);
39+
40+
return <></>;
41+
};

dotcom-rendering/src/layouts/FrontLayout.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,19 @@ const isToggleable = (
7878
index: number,
7979
collection: DCRCollectionType,
8080
isNetworkFront: boolean,
81-
isInSlimHomepageAbTestVariant: boolean,
81+
/**
82+
* The show/hide button would be covered by the MostPopularFrontRight component
83+
* in the variant of the Slim Homepage AB test.
84+
*/
85+
isTargetedContainerInSlimHomepageAbTest: boolean,
8286
) => {
8387
if (isNetworkFront) {
84-
/**
85-
* The show/hide button would be covered by the MostPopularFrontRight component
86-
* in the variant of the Slim Homepage AB test.
87-
*/
88-
const hideForSlimHomepageAbTest =
89-
isInSlimHomepageAbTestVariant &&
90-
(collection.displayName === 'News' ||
91-
collection.displayName === 'Features' ||
92-
collection.displayName === 'More features');
93-
9488
return (
9589
collection.displayName.toLowerCase() !== 'headlines' &&
9690
!isNavList(collection) &&
9791
!isHighlights(collection) &&
9892
!isLabs(collection) &&
99-
!hideForSlimHomepageAbTest
93+
!isTargetedContainerInSlimHomepageAbTest
10094
);
10195
}
10296

@@ -316,9 +310,10 @@ export const FrontLayout = ({ front, NAV }: Props) => {
316310
* content on the right-hand side. Other sections remain full-width.
317311
*/
318312
const isTargetedContainerInSlimHomepageAbTest =
319-
collection.displayName === 'News' ||
320-
collection.displayName === 'Features' ||
321-
collection.displayName === 'More features';
313+
isInSlimHomepageAbTestVariant &&
314+
(collection.displayName === 'News' ||
315+
collection.displayName === 'Features' ||
316+
collection.displayName === 'More features');
322317

323318
if (collection.collectionType === 'scrollable/highlights') {
324319
// Highlights are rendered in the Masthead component
@@ -499,7 +494,7 @@ export const FrontLayout = ({ front, NAV }: Props) => {
499494
index,
500495
collection,
501496
front.isNetworkFront,
502-
isInSlimHomepageAbTestVariant,
497+
isTargetedContainerInSlimHomepageAbTest,
503498
)}
504499
leftContent={decideLeftContent(
505500
front,
@@ -540,7 +535,6 @@ export const FrontLayout = ({ front, NAV }: Props) => {
540535
)}
541536
isLabs={isLabs(collection)}
542537
slimifySectionForAbTest={
543-
isInSlimHomepageAbTestVariant &&
544538
isTargetedContainerInSlimHomepageAbTest
545539
}
546540
mostViewed={front.mostViewed}

0 commit comments

Comments
 (0)