Skip to content

Commit 7015095

Browse files
authored
feat(cache): use cache more often (#8238)
* feat(cache): `use cache` more often * fixup! * fixup!
1 parent 6797f18 commit 7015095

File tree

10 files changed

+23
-47
lines changed

10 files changed

+23
-47
lines changed

apps/site/app/[locale]/download/archive/[version]/page.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { notFound, redirect } from 'next/navigation';
22
import type { FC } from 'react';
33

44
import provideReleaseData from '#site/next-data/providers/releaseData';
5+
import provideReleaseVersions from '#site/next-data/providers/releaseVersions';
56
import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs';
6-
import { ARCHIVE_DYNAMIC_ROUTES } from '#site/next.dynamic.constants.mjs';
77
import * as basePage from '#site/next.dynamic.page.mjs';
88
import { defaultLocale } from '#site/next.locales.mjs';
99
import type { DynamicParams } from '#site/types';
@@ -29,7 +29,9 @@ export const generateStaticParams = async () => {
2929
return [];
3030
}
3131

32-
return ARCHIVE_DYNAMIC_ROUTES.map(version => ({
32+
const versions = await provideReleaseVersions();
33+
34+
return versions.map(version => ({
3335
locale: defaultLocale.code,
3436
version,
3537
}));
@@ -53,8 +55,10 @@ const getPage: FC<PageParams> = async props => {
5355
redirect(`/${locale}/download/archive/${release?.versionWithPrefix}`);
5456
}
5557

58+
const versions = await provideReleaseVersions();
59+
5660
// Verifies if the current route is a dynamic route
57-
const isDynamicRoute = ARCHIVE_DYNAMIC_ROUTES.some(r => r.includes(pathname));
61+
const isDynamicRoute = versions.some(r => r.includes(pathname));
5862

5963
// Gets the Markdown content and context for Download Archive pages
6064
const [content, context] = await basePage.getMarkdownContext({

apps/site/components/EOL/EOLReleaseTable/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import EOLReleaseTableBody from './TableBody';
99

1010
const EOLReleaseTable: FC = async () => {
1111
const releaseData = await provideReleaseData();
12-
const vulnerabilities = provideVulnerabilities();
12+
const vulnerabilities = await provideVulnerabilities();
1313

1414
const eolReleases = releaseData.filter(
1515
release => release.status === EOL_VERSION_IDENTIFIER

apps/site/components/withSupporters.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import type { FC, PropsWithChildren } from 'react';
44

5-
import SupportersList from './Common/Supporters';
6-
75
import provideSupporters from '#site/next-data/providers/supportersData';
86

9-
const WithSupporters: FC<PropsWithChildren> = () => {
10-
const supporters = provideSupporters();
7+
import SupportersList from './Common/Supporters';
8+
9+
const WithSupporters: FC<PropsWithChildren> = async () => {
10+
const supporters = await provideSupporters();
1111

1212
return (
1313
<div className="flex max-w-full flex-wrap items-center gap-1">

apps/site/next-data/generators/supportersData.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ async function fetchOpenCollectiveData() {
2525
return members;
2626
}
2727

28-
export { fetchOpenCollectiveData };
28+
export default fetchOpenCollectiveData;
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use cache';
22

3-
import generateReleaseData from '#site/next-data/generators/releaseData.mjs';
4-
5-
const provideReleaseData = async () => generateReleaseData();
3+
import provideReleaseData from '#site/next-data/generators/releaseData.mjs';
64

75
export default provideReleaseData;
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { cache } from 'react';
1+
'use cache';
22

3-
import generateAllVersionsData from '#site/next-data/generators/releaseVersions.mjs';
4-
5-
const releaseVersions = await generateAllVersionsData();
6-
7-
const provideReleaseVersions = cache(() => releaseVersions);
3+
import provideReleaseVersions from '#site/next-data/generators/releaseVersions.mjs';
84

95
export default provideReleaseVersions;

apps/site/next-data/providers/supportersData.mjs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use cache';
2+
3+
import provideSupporters from '#site/next-data/generators/supportersData.mjs';
4+
5+
export default provideSupporters;
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { cache } from 'react';
1+
'use cache';
22

3-
import generateVulnerabilities from '#site/next-data/generators/vulnerabilities.mjs';
4-
5-
const vulnerabilities = await generateVulnerabilities();
6-
7-
const provideVulnerabilities = cache(() => vulnerabilities);
3+
import provideVulnerabilities from '#site/next-data/generators/vulnerabilities.mjs';
84

95
export default provideVulnerabilities;

apps/site/next.dynamic.constants.mjs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
import { provideBlogPosts } from '#site/next-data/providers/blogData';
4-
import provideReleaseVersions from '#site/next-data/providers/releaseVersions';
54
import { blogData } from '#site/next.json.mjs';
65

76
import { BASE_PATH, BASE_URL } from './next.constants.mjs';
@@ -28,19 +27,6 @@ export const BLOG_DYNAMIC_ROUTES = [
2827
.flat(),
2928
];
3029

31-
/**
32-
* This constant is used to create static routes on-the-fly that do not have a file-system
33-
* counterpart route. This is useful for providing routes with matching Layout Names
34-
* but that do not have Markdown content and a matching file for the route
35-
*
36-
* @type {Array<string>} A Map of pathname and Layout Name
37-
*/
38-
export const ARCHIVE_DYNAMIC_ROUTES = [
39-
// Creates dynamic routes for downloads archive pages for each version
40-
// (e.g., /download/archive/v18.20.8, /download/archive/v20.19.2)
41-
...provideReleaseVersions(),
42-
];
43-
4430
/**
4531
* This is the default Next.js Page Metadata for all pages
4632
*

0 commit comments

Comments
 (0)