@@ -8,11 +8,13 @@ import {
8
8
import { availableLocaleCodes } from '@/next.locales.mjs' ;
9
9
import type { DownloadSnippet } from '@/types' ;
10
10
11
- const getDownloadSnippets = ( lang : string ) : Promise < Array < DownloadSnippet > > => {
11
+ export default async function getDownloadSnippets (
12
+ lang : string
13
+ ) : Promise < Array < DownloadSnippet > > {
12
14
// Prevents attempting to retrieve data for an unsupported language as both the generator
13
15
// 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 [ ] ;
16
18
}
17
19
18
20
const IS_NOT_VERCEL_RUNTIME_ENV =
@@ -24,9 +26,10 @@ const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
24
26
// the data directly within the current thread, which will anyways be loaded only once
25
27
// We use lazy-imports to prevent `provideBlogData` from executing on import
26
28
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'
29
31
) ;
32
+ return provideDownloadSnippets ( lang ) ! ;
30
33
}
31
34
32
35
// Applies the language to the URL, since this content is actually localized
@@ -41,9 +44,6 @@ const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
41
44
// outdated information being shown to the user.
42
45
// Note: We do manual JSON.parse after response.text() to prevent React from throwing an Error
43
46
// 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