Skip to content

Commit aebf63f

Browse files
fixup! make site work with the Cloudflare OpenNext adapter
remove all changes related to async context
1 parent cc9d071 commit aebf63f

File tree

15 files changed

+45
-64
lines changed

15 files changed

+45
-64
lines changed

apps/site/app/[locale]/feed/[feed]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const GET = async (_: Request, props: StaticParams) => {
1414
const params = await props.params;
1515

1616
// Generate the Feed for the given feed type (blog, releases, etc)
17-
const websiteFeed = await provideWebsiteFeeds(params.feed);
17+
const websiteFeed = provideWebsiteFeeds(params.feed);
1818

1919
return new NextResponse(websiteFeed, {
2020
headers: { 'Content-Type': 'application/xml' },

apps/site/app/[locale]/next-data/api-data/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const getPathnameForApiFile = (name: string, version: string) =>
2121
// for a digest and metadata of all API pages from the Node.js Website
2222
// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers
2323
export const GET = async () => {
24-
const releases = await provideReleaseData();
24+
const releases = provideReleaseData();
2525

2626
const { versionWithPrefix } = releases.find(
2727
release => release.status === 'LTS'

apps/site/app/[locale]/next-data/blog-data/[category]/[page]/route.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ export const GET = async (_: Request, props: StaticParams) => {
2020

2121
const requestedPage = Number(params.page);
2222

23-
const data = await (requestedPage >= 1
24-
? // This allows us to blindly get all blog posts from a given category
25-
// if the page number is 0 or something smaller than 1
26-
providePaginatedBlogPosts(params.category, requestedPage)
27-
: provideBlogPosts(params.category));
23+
const data =
24+
requestedPage >= 1
25+
? // This allows us to blindly get all blog posts from a given category
26+
// if the page number is 0 or something smaller than 1
27+
providePaginatedBlogPosts(params.category, requestedPage)
28+
: provideBlogPosts(params.category);
2829

2930
return Response.json(data, { status: data.posts.length ? 200 : 404 });
3031
};

apps/site/app/[locale]/next-data/download-snippets/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const GET = async (_: Request, props: StaticParams) => {
1111
const params = await props.params;
1212

1313
// Retrieve all available Download snippets for a given locale if available
14-
const snippets = await provideDownloadSnippets(params.locale);
14+
const snippets = provideDownloadSnippets(params.locale);
1515

1616
// We append always the default/fallback snippets when a result is found
1717
return Response.json(snippets, {

apps/site/app/[locale]/next-data/release-data/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { defaultLocale } from '@/next.locales.mjs';
55
// for generating static data related to the Node.js Release Data
66
// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers
77
export const GET = async () => {
8-
const releaseData = await provideReleaseData();
8+
const releaseData = provideReleaseData();
99

1010
return Response.json(releaseData);
1111
};

apps/site/app/[locale]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const getPage: FC<DynamicParams> = async props => {
9292
// Gets the current full pathname for a given path
9393
const pathname = dynamicRouter.getPathname(path);
9494

95-
const staticGeneratedLayout = (await DYNAMIC_ROUTES()).get(pathname);
95+
const staticGeneratedLayout = DYNAMIC_ROUTES.get(pathname);
9696

9797
// If the current pathname is a statically generated route
9898
// it means it does not have a Markdown file nor exists under the filesystem

apps/site/components/withDownloadSection.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ import getDownloadSnippets from '@/next-data/downloadSnippets';
77
import getReleaseData from '@/next-data/releaseData';
88
import { defaultLocale } from '@/next.locales.mjs';
99
import { ReleaseProvider, ReleasesProvider } from '@/providers/releaseProvider';
10-
import type { DownloadSnippet } from '@/types';
1110

1211
// By default the translated languages do not contain all the download snippets
1312
// Hence we always merge any translated snippet with the fallbacks for missing snippets
14-
let fallbackSnippets: Array<DownloadSnippet>;
13+
const fallbackSnippets = await getDownloadSnippets(defaultLocale.code);
1514

1615
const WithDownloadSection: FC<PropsWithChildren> = async ({ children }) => {
17-
fallbackSnippets ??= await getDownloadSnippets(defaultLocale.code);
18-
1916
const locale = await getLocale();
2017
const releases = await getReleaseData();
2118
const snippets = await getDownloadSnippets(locale);

apps/site/next-data/downloadSnippets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default async function getDownloadSnippets(
2929
const { default: provideDownloadSnippets } = await import(
3030
'@/next-data/providers/downloadSnippets'
3131
);
32-
return (await provideDownloadSnippets(lang))!;
32+
return provideDownloadSnippets(lang)!;
3333
}
3434

3535
// Applies the language to the URL, since this content is actually localized

apps/site/next-data/providers/blogData.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@ import { cache } from 'react';
22

33
import generateBlogData from '@/next-data/generators/blogData.mjs';
44
import { BLOG_POSTS_PER_PAGE } from '@/next.constants.mjs';
5-
import type { BlogCategory, BlogPostsRSC, BlogPost } from '@/types';
5+
import type { BlogCategory, BlogPostsRSC } from '@/types';
66

7-
let blogData: {
8-
categories: Array<BlogCategory>;
9-
posts: Array<BlogPost>;
10-
};
7+
const { categories, posts } = await generateBlogData();
118

12-
export const provideBlogCategories = cache(async () => {
13-
blogData ??= await generateBlogData();
14-
return blogData.categories;
15-
});
9+
export const provideBlogCategories = cache(() => categories);
1610

1711
export const provideBlogPosts = cache(
18-
async (category: BlogCategory): Promise<BlogPostsRSC> => {
19-
blogData ??= await generateBlogData();
20-
const categoryPosts = blogData.posts
12+
(category: BlogCategory): BlogPostsRSC => {
13+
const categoryPosts = posts
2114
.filter(post => post.categories.includes(category))
2215
.sort((a, b) => b.date.getTime() - a.date.getTime());
2316

@@ -39,8 +32,8 @@ export const provideBlogPosts = cache(
3932
);
4033

4134
export const providePaginatedBlogPosts = cache(
42-
async (category: BlogCategory, page: number): Promise<BlogPostsRSC> => {
43-
const { posts, pagination } = await provideBlogPosts(category);
35+
(category: BlogCategory, page: number): BlogPostsRSC => {
36+
const { posts, pagination } = provideBlogPosts(category);
4437

4538
// This autocorrects if invalid numbers are given to only allow
4639
// actual valid numbers to be provided

apps/site/next-data/providers/downloadSnippets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { cache } from 'react';
22

33
import generateDownloadSnippets from '@/next-data/generators/downloadSnippets.mjs';
44

5-
const provideDownloadSnippets = cache(async (language: string) => {
6-
const downloadSnippets = await generateDownloadSnippets();
5+
const downloadSnippets = await generateDownloadSnippets();
76

7+
const provideDownloadSnippets = cache((language: string) => {
88
if (downloadSnippets.has(language)) {
99
return downloadSnippets.get(language)!;
1010
}

0 commit comments

Comments
 (0)