@@ -8,11 +8,13 @@ import {
88import { availableLocaleCodes } from '@/next.locales.mjs' ;
99import type { DownloadSnippet } from '@/types' ;
1010
11- const getDownloadSnippets = ( lang : string ) : Promise < Array < DownloadSnippet > > => {
11+ export default async function getDownloadSnippets (
12+ lang : string
13+ ) : Promise < Array < DownloadSnippet > > {
1214 // Prevents attempting to retrieve data for an unsupported language as both the generator
1315 // and the API endpoint will simply return 404. And we want to prevent a 404 response.
14- if ( availableLocaleCodes . includes ( lang ) === false ) {
15- return Promise . resolve ( [ ] ) ;
16+ if ( ! availableLocaleCodes . includes ( lang ) ) {
17+ return [ ] ;
1618 }
1719
1820 const IS_NOT_VERCEL_RUNTIME_ENV =
@@ -24,9 +26,10 @@ const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
2426 // the data directly within the current thread, which will anyways be loaded only once
2527 // We use lazy-imports to prevent `provideBlogData` from executing on import
2628 if ( ENABLE_STATIC_EXPORT || IS_NOT_VERCEL_RUNTIME_ENV ) {
27- return import ( '@/next-data/providers/downloadSnippets' ) . then (
28- ( { default : provideDownloadSnippets } ) => provideDownloadSnippets ( lang ) !
29+ const { default : provideDownloadSnippets } = await import (
30+ '@/next-data/providers/downloadSnippets'
2931 ) ;
32+ return provideDownloadSnippets ( lang ) ! ;
3033 }
3134
3235 // Applies the language to the URL, since this content is actually localized
@@ -41,9 +44,6 @@ const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
4144 // outdated information being shown to the user.
4245 // Note: We do manual JSON.parse after response.text() to prevent React from throwing an Error
4346 // that does not provide a clear stack trace of which request is failing and what the JSON.parse error is
44- return fetch ( fetchURL )
45- . then ( response => response . text ( ) )
46- . then ( JSON . parse ) ;
47- } ;
48-
49- export default getDownloadSnippets ;
47+ const response = await fetch ( fetchURL ) ;
48+ return JSON . parse ( await response . text ( ) ) ;
49+ }
0 commit comments