11import {
22 ENABLE_STATIC_EXPORT ,
3- IS_DEVELOPMENT ,
3+ IS_DEV_ENV ,
44 NEXT_DATA_URL ,
55 VERCEL_ENV ,
66} from '@/next.constants.mjs' ;
77import { availableLocaleCodes } from '@/next.locales.mjs' ;
88import type { DownloadSnippet } from '@/types' ;
99
10- // Prevents React from throwing an Error when not able to fulfil a request
11- // due to internal processing errors
12- const parseDownloadSnippetResponse = ( data : string ) : Array < DownloadSnippet > =>
13- data . startsWith ( '{' ) ? JSON . parse ( data ) : [ ] ;
14-
1510const getDownloadSnippets = ( lang : string ) : Promise < Array < DownloadSnippet > > => {
1611 // Prevents attempting to retrieve data for an unsupported language as both the generator
1712 // and the API endpoint will simply return 404. And we want to prevent a 404 response.
@@ -23,7 +18,7 @@ const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
2318 // hence the self-ingestion APIs will not be available. In this case we want to load
2419 // the data directly within the current thread, which will anyways be loaded only once
2520 // We use lazy-imports to prevent `provideBlogData` from executing on import
26- if ( ENABLE_STATIC_EXPORT || ( ! IS_DEVELOPMENT && ! VERCEL_ENV ) ) {
21+ if ( ENABLE_STATIC_EXPORT || ( VERCEL_ENV !== 'production' && ! IS_DEV_ENV ) ) {
2722 return import ( '@/next-data/providers/downloadSnippets' ) . then (
2823 ( { default : provideDownloadSnippets } ) => provideDownloadSnippets ( lang ) !
2924 ) ;
@@ -43,7 +38,7 @@ const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
4338 // that does not provide a clear stack trace of which request is failing and what the JSON.parse error is
4439 return fetch ( fetchURL )
4540 . then ( response => response . text ( ) )
46- . then ( response => parseDownloadSnippetResponse ( response ) ) ;
41+ . then ( JSON . parse ) ;
4742} ;
4843
4944export default getDownloadSnippets ;
0 commit comments