Skip to content

Commit 02f654d

Browse files
authored
sendReact takes node not component (#14292)
The current definition prevents any props being passed to the component.
1 parent c2e1cce commit 02f654d

File tree

7 files changed

+48
-39
lines changed

7 files changed

+48
-39
lines changed

dotcom-rendering/src/devServer/routers/amp.ts renamed to dotcom-rendering/src/devServer/routers/amp.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { sendReact } from '../send';
66

77
const amp = express.Router();
88

9-
amp.get('/', sendReact('AMP', Amp));
10-
amp.get('/article', sendReact('Article', Article));
11-
amp.get('/interactive', sendReact('Interactive', Interactive));
9+
amp.get('/', sendReact('AMP', <Amp />));
10+
amp.get('/article', sendReact('Article', <Article />));
11+
amp.get('/interactive', sendReact('Interactive', <Interactive />));
1212

1313
export { amp };

dotcom-rendering/src/devServer/routers/dotcom.ts renamed to dotcom-rendering/src/devServer/routers/dotcom.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,32 @@ import { sendReact } from '../send';
1515

1616
const dotcom = Router();
1717

18-
dotcom.get('/', sendReact('Dotcom', Dotcom));
19-
dotcom.get('/article', sendReact('Article', Article));
20-
dotcom.get('/front', sendReact('Front', Front));
21-
dotcom.get('/tag-page', sendReact('Tag Page', TagPage));
22-
dotcom.get('/interactive', sendReact('Interactive', Interactive));
23-
dotcom.get('/newsletters', sendReact('All Newsletters', Newsletters));
24-
dotcom.get('/football-live', sendReact('Football Live', FootballLive));
18+
dotcom.get('/', sendReact('Dotcom', <Dotcom />));
19+
dotcom.get('/article', sendReact('Article', <Article />));
20+
dotcom.get('/front', sendReact('Front', <Front />));
21+
dotcom.get('/tag-page', sendReact('Tag Page', <TagPage />));
22+
dotcom.get('/interactive', sendReact('Interactive', <Interactive />));
23+
dotcom.get('/newsletters', sendReact('All Newsletters', <Newsletters />));
24+
dotcom.get('/football-live', sendReact('Football Live', <FootballLive />));
2525
dotcom.get(
2626
'/football-fixtures',
27-
sendReact('Football Fixtures', FootballFixtures),
27+
sendReact('Football Fixtures', <FootballFixtures />),
28+
);
29+
dotcom.get(
30+
'/football-results',
31+
sendReact('Football Results', <FootballResults />),
32+
);
33+
dotcom.get(
34+
'/football-tables',
35+
sendReact('Football Tables', <FootballTables />),
2836
);
29-
dotcom.get('/football-results', sendReact('Football Results', FootballResults));
30-
dotcom.get('/football-tables', sendReact('Football Tables', FootballTables));
3137
dotcom.get(
3238
'/football-match-summary',
33-
sendReact('Football Match Summary', FootballMatchSummary),
39+
sendReact('Football Match Summary', <FootballMatchSummary />),
3440
);
3541
dotcom.get(
3642
'/cricket-scorecard',
37-
sendReact('Cricket Scorecard', CricketScorecard),
43+
sendReact('Cricket Scorecard', <CricketScorecard />),
3844
);
3945

4046
export { dotcom };

dotcom-rendering/src/devServer/routers/editionsApp.ts renamed to dotcom-rendering/src/devServer/routers/editionsApp.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { sendReact } from '../send';
55

66
const editionsApp = express.Router();
77

8-
editionsApp.get('/', sendReact('Editions App', EditionsApp));
8+
editionsApp.get('/', sendReact('Editions App', <EditionsApp />));
99
editionsApp.get(
1010
'/crosswords',
11-
sendReact('Editions Crosswords', EditionsCrosswords),
11+
sendReact('Editions Crosswords', <EditionsCrosswords />),
1212
);
1313

1414
export { editionsApp };

dotcom-rendering/src/devServer/routers/liveApps.ts renamed to dotcom-rendering/src/devServer/routers/liveApps.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { sendReact } from '../send';
66

77
const liveApps = express.Router();
88

9-
liveApps.get('/', sendReact('Live Apps', LiveApps));
10-
liveApps.get('/article', sendReact('Article', Article));
11-
liveApps.get('/interactive', sendReact('Interactive', Interactive));
9+
liveApps.get('/', sendReact('Live Apps', <LiveApps />));
10+
liveApps.get('/article', sendReact('Article', <Article />));
11+
liveApps.get('/interactive', sendReact('Interactive', <Interactive />));
1212

1313
export { liveApps };

dotcom-rendering/src/devServer/routers/pages.ts renamed to dotcom-rendering/src/devServer/routers/pages.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,33 @@ import { sendReact } from '../send';
1616

1717
const pages = Router();
1818

19-
pages.get('/', sendReact('Pages', Pages));
20-
pages.get('/article', sendReact('Article', Article));
21-
pages.get('/front', sendReact('Front', Front));
22-
pages.get('/tag-page', sendReact('Tag Page', TagPage));
23-
pages.get('/interactive', sendReact('Interactive', Interactive));
24-
pages.get('/newsletters', sendReact('All Newsletters', Newsletters));
19+
pages.get('/', sendReact('Pages', <Pages />));
20+
pages.get('/article', sendReact('Article', <Article />));
21+
pages.get('/front', sendReact('Front', <Front />));
22+
pages.get('/tag-page', sendReact('Tag Page', <TagPage />));
23+
pages.get('/interactive', sendReact('Interactive', <Interactive />));
24+
pages.get('/newsletters', sendReact('All Newsletters', <Newsletters />));
2525
pages.get(
2626
'/editions-crosswords',
27-
sendReact('Editions Crosswords', EditionsCrosswords),
27+
sendReact('Editions Crosswords', <EditionsCrosswords />),
2828
);
29-
pages.get('/football-live', sendReact('Football Live', FootballLive));
29+
pages.get('/football-live', sendReact('Football Live', <FootballLive />));
3030
pages.get(
3131
'/football-fixtures',
32-
sendReact('Football Fixtures', FootballFixtures),
32+
sendReact('Football Fixtures', <FootballFixtures />),
3333
);
34-
pages.get('/football-results', sendReact('Football Results', FootballResults));
35-
pages.get('/football-tables', sendReact('Football Tables', FootballTables));
34+
pages.get(
35+
'/football-results',
36+
sendReact('Football Results', <FootballResults />),
37+
);
38+
pages.get('/football-tables', sendReact('Football Tables', <FootballTables />));
3639
pages.get(
3740
'/football-match-summary',
38-
sendReact('Football Match Summary', FootballMatchSummary),
41+
sendReact('Football Match Summary', <FootballMatchSummary />),
3942
);
4043
pages.get(
4144
'/cricket-scorecard',
42-
sendReact('Cricket Scorecard', CricketScorecard),
45+
sendReact('Cricket Scorecard', <CricketScorecard />),
4346
);
4447

4548
export { pages };

dotcom-rendering/src/devServer/routers/targets.ts renamed to dotcom-rendering/src/devServer/routers/targets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { liveApps } from './liveApps';
88

99
const targets = Router();
1010

11-
targets.get('/', sendReact('Targets', Targets));
11+
targets.get('/', sendReact('Targets', <Targets />));
1212
targets.use('/dotcom', dotcom);
1313
targets.use('/live-apps', liveApps);
1414
targets.use('/editions-app', editionsApp);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import path from 'node:path';
22
import type { RequestHandler } from 'express';
3-
import type { FunctionComponent } from 'react';
3+
import type { ReactNode } from 'react';
44
import { renderToPipeableStream } from 'react-dom/server';
55
import { Doc } from './docs/doc';
66

7-
export const sendReact =
8-
(title: string, Component: FunctionComponent): RequestHandler =>
9-
(req, res) => {
7+
export function sendReact(title: string, node: ReactNode): RequestHandler {
8+
return (req, res) => {
109
const element = (
1110
<Doc title={title} path={path.join(req.baseUrl, req.path, '/')}>
12-
<Component />
11+
{node}
1312
</Doc>
1413
);
1514

@@ -20,3 +19,4 @@ export const sendReact =
2019
},
2120
});
2221
};
22+
}

0 commit comments

Comments
 (0)