Skip to content

Commit 4a826d2

Browse files
Merge pull request #13407 from bbc/WS-1400-ECT-HELMET
WS-1400: Add client side redirect to .lite site for 2g and slow 2g Users
2 parents 9a61a8c + b74ac49 commit 4a826d2

File tree

15 files changed

+251
-19
lines changed

15 files changed

+251
-19
lines changed

src/app/components/CallToActionLink/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import styles from './index.styles';
99
import CallToActionLinkContext from './CallToActionLinkContext';
1010

1111
type CallToActionLinkProps = {
12+
id?: string;
1213
url: string;
1314
className?: string;
1415
eventTrackingData?: EventTrackingData;
@@ -19,6 +20,7 @@ type CallToActionLinkProps = {
1920
};
2021

2122
const CallToActionLink = ({
23+
id,
2224
url,
2325
children,
2426
eventTrackingData,
@@ -43,6 +45,7 @@ const CallToActionLink = ({
4345

4446
return (
4547
<a
48+
{...(id && { id })}
4649
href={url}
4750
{...(eventTrackingData && clickTrackerHandler)}
4851
className={className}

src/app/components/LiteSiteSummary/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const LiteSiteSummary = () => {
4040
</Paragraph>
4141
<Paragraph data-e2e="to-main-site">
4242
<CallToActionLink
43+
id="go-back-to-canonical-link"
4344
url={canonicalLink}
4445
data-ignore-lite
4546
{...clickTrackerHandler}

src/app/hooks/useNetworkStatusTracker/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { renderHook, act } from '@testing-library/react';
22
import { renderHook as renderSSRHook } from '@testing-library/react-hooks/server';
3+
import { EffectiveNetworkType } from '#app/models/types/global';
34
import useNetworkStatus from './index';
4-
import { EffectiveNetworkType } from './type';
55

66
describe('useNetworkStatus', () => {
77
const originalNavigator = window.navigator;

src/app/hooks/useNetworkStatusTracker/index.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { useState, useEffect } from 'react';
22
import getEffectiveNetworkType from '#app/lib/utilities/getEffectiveNetworkType';
3-
import { EffectiveNetworkType, NetworkStatus } from './type';
3+
import { NetworkStatus } from './type';
44

55
/**
66
* A hook to monitor and provide real-time network connectivity status.
77
* Tracks whether the user is online or offline and includes the effective network type.
88
* @returns {NetworkStatus} An object containing isOnline (boolean), source ('browser'), and networkType (EffectiveNetworkType).
99
*/
1010

11-
interface NavigatorWithConnection extends Navigator {
12-
connection?: {
13-
effectiveType?: EffectiveNetworkType;
14-
addEventListener?: (type: string, listener: () => void) => void;
15-
removeEventListener?: (type: string, listener: () => void) => void;
16-
};
17-
}
18-
1911
const useNetworkStatusTracker = (): NetworkStatus => {
2012
const [networkStatus, setNetworkStatus] = useState<NetworkStatus>(() => {
2113
const isOnline =
@@ -58,7 +50,7 @@ const useNetworkStatusTracker = (): NetworkStatus => {
5850
window.addEventListener('online', handleOnline);
5951
window.addEventListener('offline', handleOffline);
6052

61-
const { connection } = navigator as NavigatorWithConnection;
53+
const { connection } = navigator;
6254

6355
if (connection?.addEventListener) {
6456
connection.addEventListener('change', handleConnectionChange);

src/app/hooks/useNetworkStatusTracker/type.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
export type EffectiveNetworkType =
2-
| 'slow-2g'
3-
| '2g'
4-
| '3g'
5-
| '4g'
6-
| '5g'
7-
| 'unknown';
1+
import { EffectiveNetworkType } from '#app/models/types/global';
82

93
export type NetworkStatus = {
104
isOnline: boolean;

src/app/lib/utilities/getEffectiveNetworkType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EffectiveNetworkType } from '../../hooks/useNetworkStatusTracker/type';
1+
import { EffectiveNetworkType } from '#app/models/types/global';
22

33
const getEffectiveNetworkType = (): EffectiveNetworkType => {
44
if (typeof window === 'undefined' || !navigator) {

src/app/models/types/global.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,11 @@ export type ServicesVariantsProps = {
134134
service: Services;
135135
variant?: Variants;
136136
};
137+
138+
export type EffectiveNetworkType =
139+
| 'slow-2g'
140+
| '2g'
141+
| '3g'
142+
| '4g'
143+
| '5g'
144+
| 'unknown';

src/global.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { ReverbClient } from '#models/types/eventTracking';
22
import { BumpType, Player } from '#app/components/MediaLoader/types';
3+
import { EffectiveNetworkType } from '#app/models/types/global';
34

45
declare global {
6+
interface Navigator {
7+
connection?: {
8+
effectiveType?: EffectiveNetworkType;
9+
addEventListener?: (type: string, listener: () => void) => void;
10+
removeEventListener?: (type: string, listener: () => void) => void;
11+
};
12+
}
513
interface Window {
614
bbcpage:
715
| {

src/server/Document/Renderers/CanonicalRenderer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import IfAboveIE9 from '#app/legacy/components/IfAboveIE9Comment';
44
import NO_JS_CLASSNAME from '#app/lib/noJs.const';
55
import { getProcessEnvAppVariables } from '#app/lib/utilities/getEnvConfig';
66
import serialiseForScript from '#app/lib/utilities/serialiseForScript';
7+
import CanonicalToLiteRedirect from '#src/server/utilities/CanonicalToLiteRedirect';
78
import addOperaMiniClassScript from '#app/lib/utilities/addOperaMiniClassScript';
89
import { BaseRendererProps } from './types';
910
import ReverbTemplate from './ReverbTemplate';
@@ -98,6 +99,7 @@ export default function CanonicalRenderer({
9899
return (
99100
<html lang="en-GB" className={NO_JS_CLASSNAME} {...htmlAttrs}>
100101
<head>
102+
<CanonicalToLiteRedirect />
101103
<ReverbTemplate nonce={nonce} />
102104
{isApp && <meta name="robots" content="noindex" />}
103105
{title}

src/server/Document/Renderers/LiteRenderer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable react/no-danger */
22
import { ReactElement, PropsWithChildren } from 'react';
3+
import { OptOutOfLiteRedirect } from '#src/server/utilities/CanonicalToLiteRedirect';
34
import { BaseRendererProps } from './types';
45
import ComponentTracking from './ComponentTracking';
56

@@ -24,6 +25,7 @@ export default function LitePageRenderer({
2425
{helmetMetaTags}
2526
{helmetLinkTags}
2627
<style dangerouslySetInnerHTML={{ __html: styles }} />
28+
<OptOutOfLiteRedirect />
2729
{/* IMPORTANT: ComponentTracking MUST come before helmetScriptTags due to synchronous calls from helmetScriptTags to functions within ComponentTracking */}
2830
<ComponentTracking
2931
enableStaticClickTrackingOnOperaMiniOnly={false}

0 commit comments

Comments
 (0)