Skip to content

Commit cce6766

Browse files
Allow server-side rendering (SSR) in all components
1 parent 82d59b0 commit cce6766

File tree

19 files changed

+54
-36
lines changed

19 files changed

+54
-36
lines changed

src/components/content-presentation/do-and-dont-list/DoAndDontList.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use client';
21
import React, {
32
ComponentPropsWithoutRef,
43
FC,

src/components/content-presentation/table/components/TableRow.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use client';
21
import classNames from 'classnames';
32
import React, {
43
Children,

src/components/content-presentation/tabs/Tabs.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use client';
21
import classNames from 'classnames';
32
import React, {
43
ComponentPropsWithoutRef,
@@ -9,7 +8,7 @@ import React, {
98
useState,
109
} from 'react';
1110
import HeadingLevel, { HeadingLevelProps } from '@components/utils/HeadingLevel';
12-
import { Tabs } from 'nhsuk-frontend';
11+
import { type Tabs } from 'nhsuk-frontend';
1312

1413
export type TabsProps = ComponentPropsWithoutRef<'div'>;
1514

@@ -62,7 +61,11 @@ const TabsComponent = forwardRef<HTMLDivElement, TabsProps>((props, forwardedRef
6261
return;
6362
}
6463

65-
setInstance(new Tabs(moduleRef.current));
64+
const { current: $root } = moduleRef;
65+
66+
import('nhsuk-frontend').then(({ Tabs }) => {
67+
setInstance(new Tabs($root));
68+
});
6669
}, [moduleRef, instance]);
6770

6871
return (

src/components/form-elements/button/Button.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ForwardedRef, MouseEvent, useEffect, useState, forwardRef, createRef } from 'react';
22
import { AsElementLink } from '@util/types/LinkTypes';
3-
import { Button } from 'nhsuk-frontend';
3+
import { type Button } from 'nhsuk-frontend';
44
import classNames from 'classnames';
55

66
export interface ButtonProps extends AsElementLink<HTMLButtonElement> {
@@ -44,7 +44,11 @@ const ButtonComponent = forwardRef<HTMLButtonElement, ButtonProps>((props, forwa
4444
return;
4545
}
4646

47-
setInstance(new Button(moduleRef.current));
47+
const { current: $root } = moduleRef;
48+
49+
import('nhsuk-frontend').then(({ Button }) => {
50+
setInstance(new Button($root));
51+
});
4852
}, [moduleRef, instance]);
4953

5054
return (
@@ -96,7 +100,11 @@ const ButtonLinkComponent = forwardRef<HTMLAnchorElement, ButtonLinkProps>(
96100
return;
97101
}
98102

99-
setInstance(new Button(moduleRef.current));
103+
const { current: $root } = moduleRef;
104+
105+
import('nhsuk-frontend').then(({ Button }) => {
106+
setInstance(new Button($root));
107+
});
100108
}, [moduleRef, instance]);
101109

102110
return (

src/components/form-elements/character-count/CharacterCount.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use client';
21
import React, { ComponentPropsWithoutRef, createRef, forwardRef, useEffect, useState } from 'react';
3-
import { CharacterCount } from 'nhsuk-frontend';
2+
import { type CharacterCount } from 'nhsuk-frontend';
43
import classNames from 'classnames';
54
import FormGroup from '@components/utils/FormGroup';
65
import { FormElementProps } from '@util/types/FormTypes';
@@ -23,7 +22,11 @@ const CharacterCountComponent = forwardRef<HTMLTextAreaElement, CharacterCountPr
2322
return;
2423
}
2524

26-
setInstance(new CharacterCount(moduleRef.current));
25+
const { current: $root } = moduleRef;
26+
27+
import('nhsuk-frontend').then(({ CharacterCount }) => {
28+
setInstance(new CharacterCount($root));
29+
});
2730
}, [moduleRef, instance]);
2831

2932
return (

src/components/form-elements/checkboxes/Checkboxes.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use client';
2-
31
import React, { ComponentPropsWithoutRef, createRef, forwardRef, useEffect, useState } from 'react';
42
import classNames from 'classnames';
53
import { FormElementProps } from '@util/types/FormTypes';
@@ -8,7 +6,7 @@ import CheckboxContext, { ICheckboxContext } from './CheckboxContext';
86
import CheckboxesItem from './components/Item';
97
import CheckboxesDivider from './components/Divider';
108
import { generateRandomName } from '@util/RandomID';
11-
import { Checkboxes } from 'nhsuk-frontend';
9+
import { type Checkboxes } from 'nhsuk-frontend';
1210

1311
export interface CheckboxesProps
1412
extends ComponentPropsWithoutRef<'div'>,
@@ -31,7 +29,11 @@ const CheckboxesComponent = forwardRef<HTMLDivElement, CheckboxesProps>((props,
3129
return;
3230
}
3331

34-
setInstance(new Checkboxes(moduleRef.current));
32+
const { current: $root } = moduleRef;
33+
34+
import('nhsuk-frontend').then(({ Checkboxes }) => {
35+
setInstance(new Checkboxes($root));
36+
});
3537
}, [moduleRef, instance]);
3638

3739
const getBoxId = (id: string, reference: string): string => {

src/components/form-elements/checkboxes/components/Item.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use client';
2-
31
import React, {
42
ComponentPropsWithRef,
53
ComponentPropsWithoutRef,

src/components/form-elements/date-input/DateInput.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use client';
2-
31
import React, {
42
ChangeEvent,
53
ComponentPropsWithoutRef,

src/components/form-elements/date-input/components/IndividualDateInputs.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use client';
21
import React, { ComponentPropsWithoutRef, useContext, ChangeEvent, forwardRef } from 'react';
32
import classNames from 'classnames';
43
import { FormElementProps } from '@util/types/FormTypes';

src/components/form-elements/error-summary/ErrorSummary.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import React, {
1010
import classNames from 'classnames';
1111
import { AsElementLink } from '@util/types/LinkTypes';
1212
import { childIsOfComponentType } from '@util/types/TypeGuards';
13-
import { ErrorSummary } from 'nhsuk-frontend';
13+
import { type ErrorSummary } from 'nhsuk-frontend';
1414

1515
export type TitleProps = ComponentPropsWithoutRef<'h2'>;
1616

@@ -58,7 +58,7 @@ const ListItem = forwardRef<HTMLAnchorElement, ListItemProps>((props, forwardedR
5858
);
5959
});
6060

61-
interface ErrorSummaryProps extends ComponentPropsWithoutRef<'div'> {
61+
export interface ErrorSummaryProps extends ComponentPropsWithoutRef<'div'> {
6262
disableAutoFocus?: boolean;
6363
}
6464

@@ -72,7 +72,11 @@ const ErrorSummaryComponent = forwardRef<HTMLDivElement, ErrorSummaryProps>(
7272
return;
7373
}
7474

75-
setInstance(new ErrorSummary(moduleRef.current));
75+
const { current: $root } = moduleRef;
76+
77+
import('nhsuk-frontend').then(({ ErrorSummary }) => {
78+
setInstance(new ErrorSummary($root));
79+
});
7680
}, [moduleRef, instance]);
7781

7882
const items = Children.toArray(children);

0 commit comments

Comments
 (0)