From c7f0f3811bc7d503c76d3082050697a04903f989 Mon Sep 17 00:00:00 2001 From: avivkeller Date: Sat, 3 May 2025 13:19:29 -0400 Subject: [PATCH 1/3] chore(const): add IS_NOT_VERCEL_RUNTIME_ENV --- apps/site/next-data/blogData.ts | 8 +------- apps/site/next-data/downloadSnippets.ts | 8 +------- apps/site/next-data/releaseData.ts | 8 +------- apps/site/next.constants.mjs | 3 +++ 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/apps/site/next-data/blogData.ts b/apps/site/next-data/blogData.ts index 32e2b71494bc3..a5d1f8e9d704b 100644 --- a/apps/site/next-data/blogData.ts +++ b/apps/site/next-data/blogData.ts @@ -1,9 +1,7 @@ import { ENABLE_STATIC_EXPORT, - IS_DEV_ENV, NEXT_DATA_URL, - VERCEL_ENV, - VERCEL_REGION, + IS_NOT_VERCEL_RUNTIME_ENV, } from '@/next.constants.mjs'; import type { BlogCategory, BlogPostsRSC } from '@/types'; @@ -11,10 +9,6 @@ const getBlogData = ( cat: BlogCategory, page?: number ): Promise => { - const IS_NOT_VERCEL_RUNTIME_ENV = - (!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) || - (!IS_DEV_ENV && !VERCEL_ENV); - // When we're using Static Exports the Next.js Server is not running (during build-time) // hence the self-ingestion APIs will not be available. In this case we want to load // the data directly within the current thread, which will anyways be loaded only once diff --git a/apps/site/next-data/downloadSnippets.ts b/apps/site/next-data/downloadSnippets.ts index 6fd143852204a..d371d07388c9e 100644 --- a/apps/site/next-data/downloadSnippets.ts +++ b/apps/site/next-data/downloadSnippets.ts @@ -1,9 +1,7 @@ import { ENABLE_STATIC_EXPORT, - IS_DEV_ENV, NEXT_DATA_URL, - VERCEL_ENV, - VERCEL_REGION, + IS_NOT_VERCEL_RUNTIME_ENV, } from '@/next.constants.mjs'; import { availableLocaleCodes } from '@/next.locales.mjs'; import type { DownloadSnippet } from '@/types'; @@ -17,10 +15,6 @@ export default async function getDownloadSnippets( return []; } - const IS_NOT_VERCEL_RUNTIME_ENV = - (!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) || - (!IS_DEV_ENV && !VERCEL_ENV); - // When we're using Static Exports the Next.js Server is not running (during build-time) // hence the self-ingestion APIs will not be available. In this case we want to load // the data directly within the current thread, which will anyways be loaded only once diff --git a/apps/site/next-data/releaseData.ts b/apps/site/next-data/releaseData.ts index e04c4c9373d15..deafe804129a0 100644 --- a/apps/site/next-data/releaseData.ts +++ b/apps/site/next-data/releaseData.ts @@ -1,17 +1,11 @@ import { ENABLE_STATIC_EXPORT, - IS_DEV_ENV, NEXT_DATA_URL, - VERCEL_ENV, - VERCEL_REGION, + IS_NOT_VERCEL_RUNTIME_ENV, } from '@/next.constants.mjs'; import type { NodeRelease } from '@/types'; const getReleaseData = (): Promise> => { - const IS_NOT_VERCEL_RUNTIME_ENV = - (!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) || - (!IS_DEV_ENV && !VERCEL_ENV); - // When we're using Static Exports the Next.js Server is not running (during build-time) // hence the self-ingestion APIs will not be available. In this case we want to load // the data directly within the current thread, which will anyways be loaded only once diff --git a/apps/site/next.constants.mjs b/apps/site/next.constants.mjs index 52439c1454bee..0cfb1cc912857 100644 --- a/apps/site/next.constants.mjs +++ b/apps/site/next.constants.mjs @@ -23,6 +23,9 @@ export const VERCEL_ENV = process.env.VERCEL_ENV || undefined; */ export const VERCEL_REGION = process.env.VERCEL_REGION || undefined; +export const IS_NOT_VERCEL_RUNTIME_ENV = + (!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) || (!IS_DEV_ENV && !VERCEL_ENV); + /** * This is used for telling Next.js to do a Static Export Build of the Website * From 3b1a62d953a378d150403872dc7318386c618214 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sat, 3 May 2025 13:21:42 -0400 Subject: [PATCH 2/3] finally a good copilot suggestion Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Aviv Keller --- apps/site/next.constants.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/site/next.constants.mjs b/apps/site/next.constants.mjs index 0cfb1cc912857..17109fbf6c8a6 100644 --- a/apps/site/next.constants.mjs +++ b/apps/site/next.constants.mjs @@ -23,6 +23,15 @@ export const VERCEL_ENV = process.env.VERCEL_ENV || undefined; */ export const VERCEL_REGION = process.env.VERCEL_REGION || undefined; +/** + * This constant determines if the current environment is NOT a Vercel runtime environment. + * + * The logic is as follows: + * - If we are NOT in a development environment (`!IS_DEV_ENV`) AND: + * - Vercel environment variable (`VERCEL_ENV`) is defined but the Vercel region (`VERCEL_REGION`) is NOT defined, OR + * - Vercel environment variable (`VERCEL_ENV`) is NOT defined at all. + * This helps identify cases where the application is running outside of Vercel's runtime environment. + */ export const IS_NOT_VERCEL_RUNTIME_ENV = (!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) || (!IS_DEV_ENV && !VERCEL_ENV); From 60e8292ed52b9e4ad594edd49408095a15da9b15 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sat, 3 May 2025 14:30:32 -0400 Subject: [PATCH 3/3] pull out `!IS_DEV_ENV` Signed-off-by: Aviv Keller --- apps/site/next.constants.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/next.constants.mjs b/apps/site/next.constants.mjs index 17109fbf6c8a6..309093b7b5dcd 100644 --- a/apps/site/next.constants.mjs +++ b/apps/site/next.constants.mjs @@ -33,7 +33,7 @@ export const VERCEL_REGION = process.env.VERCEL_REGION || undefined; * This helps identify cases where the application is running outside of Vercel's runtime environment. */ export const IS_NOT_VERCEL_RUNTIME_ENV = - (!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) || (!IS_DEV_ENV && !VERCEL_ENV); + !IS_DEV_ENV && ((VERCEL_ENV && !VERCEL_REGION) || !VERCEL_ENV); /** * This is used for telling Next.js to do a Static Export Build of the Website