Skip to content

Commit 93bbe70

Browse files
committed
fix: erroneous env usage for fetch
1 parent 119765d commit 93bbe70

5 files changed

Lines changed: 11 additions & 21 deletions

File tree

apps/site/next-data/blogData.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import {
22
ENABLE_STATIC_EXPORT,
3-
IS_DEVELOPMENT,
3+
IS_DEV_ENV,
44
NEXT_DATA_URL,
55
VERCEL_ENV,
66
} from '@/next.constants.mjs';
77
import type { BlogPostsRSC } from '@/types';
88

9-
// Prevents React from throwing an Error when not able to fulfil a request
10-
// due to missing category or internal processing errors
11-
const parseBlogDataResponse = (data: string): BlogPostsRSC =>
12-
data.startsWith('{') ? JSON.parse(data) : { posts: [], pagination: {} };
13-
149
const getBlogData = (cat: string, page?: number): Promise<BlogPostsRSC> => {
1510
// When we're using Static Exports the Next.js Server is not running (during build-time)
1611
// hence the self-ingestion APIs will not be available. In this case we want to load
1712
// the data directly within the current thread, which will anyways be loaded only once
1813
// We use lazy-imports to prevent `provideBlogData` from executing on import
19-
if (ENABLE_STATIC_EXPORT || (!IS_DEVELOPMENT && !VERCEL_ENV)) {
14+
if (ENABLE_STATIC_EXPORT || (VERCEL_ENV !== 'production' && !IS_DEV_ENV)) {
2015
return import('@/next-data/providers/blogData').then(
2116
({ provideBlogPosts, providePaginatedBlogPosts }) =>
2217
page ? providePaginatedBlogPosts(cat, page) : provideBlogPosts(cat)
@@ -29,7 +24,7 @@ const getBlogData = (cat: string, page?: number): Promise<BlogPostsRSC> => {
2924
// outdated information being shown to the user.
3025
return fetch(fetchURL)
3126
.then(response => response.text())
32-
.then(response => parseBlogDataResponse(response));
27+
.then(JSON.parse);
3328
};
3429

3530
export default getBlogData;

apps/site/next-data/downloadSnippets.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import {
22
ENABLE_STATIC_EXPORT,
3-
IS_DEVELOPMENT,
3+
IS_DEV_ENV,
44
NEXT_DATA_URL,
55
VERCEL_ENV,
66
} from '@/next.constants.mjs';
77
import { availableLocaleCodes } from '@/next.locales.mjs';
88
import 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-
1510
const 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

4944
export default getDownloadSnippets;

apps/site/next-data/releaseData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
ENABLE_STATIC_EXPORT,
3-
IS_DEVELOPMENT,
3+
IS_DEV_ENV,
44
NEXT_DATA_URL,
55
VERCEL_ENV,
66
} from '@/next.constants.mjs';
@@ -11,7 +11,7 @@ const getReleaseData = (): Promise<Array<NodeRelease>> => {
1111
// hence the self-ingestion APIs will not be available. In this case we want to load
1212
// the data directly within the current thread, which will anyways be loaded only once
1313
// We use lazy-imports to prevent `provideBlogData` from executing on import
14-
if (ENABLE_STATIC_EXPORT || (!IS_DEVELOPMENT && !VERCEL_ENV)) {
14+
if (ENABLE_STATIC_EXPORT || (VERCEL_ENV !== 'production' && !IS_DEV_ENV)) {
1515
return import('@/next-data/providers/releaseData').then(
1616
({ default: provideReleaseData }) => provideReleaseData()
1717
);

apps/site/next.constants.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This is used to verify if the current Website is running on a Development Environment
55
*/
6-
export const IS_DEVELOPMENT = process.env.NODE_ENV === 'development';
6+
export const IS_DEV_ENV = process.env.NODE_ENV === 'development';
77

88
/**
99
* This is used for telling Next.js if the Website is deployed on Vercel

apps/site/next.dynamic.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
BASE_URL,
1313
DEFAULT_CATEGORY_OG_TYPE,
1414
ENABLE_STATIC_EXPORT,
15-
IS_DEVELOPMENT,
15+
IS_DEV_ENV,
1616
} from './next.constants.mjs';
1717
import {
1818
DYNAMIC_ROUTES,
@@ -42,7 +42,7 @@ const mapPathToRoute = (locale = defaultLocale.code, path = '') => ({
4242
// Provides an in-memory Map that lasts the whole build process
4343
// and disabled when on development mode (stubbed)
4444
const createCachedMarkdownCache = () => {
45-
if (IS_DEVELOPMENT) {
45+
if (IS_DEV_ENV) {
4646
return {
4747
has: () => false,
4848
set: () => {},

0 commit comments

Comments
 (0)