HackAtUCI / irvinehacks-site

Site for IrvineHacks 2024 through 2025
https://irvinehacks.com
1 stars 1 forks source link

`NEXT_PUBLIC_VERCEL_URL` incorrectly reused from build cache for site #290

Closed taesungh closed 10 months ago

taesungh commented 10 months ago

In some recent deployments, the server-side API calls were going to a different deployment because the NEXT_PUBLIC_VERCEL_URL was being baked into the build, and the Turborepo cache doesn't consider this as an input.

All NEXT_PUBLIC_ variables will be frozen with the value evaluated at build time, so these values need to be set appropriately when the project is built (Configuring: Environment Variables, Next.js)

If we do specify NEXT_PUBLIC_VERCEL_URL as a cache input key, this means we will never be able to utilize the cache since this environment variable changes for each deployment. To avoid this, we might be able to use a dynamic lookup to prevent inlining as shown in the documentation example.

// This will NOT be inlined, because it uses a variable
const varName = 'NEXT_PUBLIC_ANALYTICS_ID'
setupAnalyticsService(process.env[varName])

// This will NOT be inlined, because it uses a variable
const env = process.env
setupAnalyticsService(env.NEXT_PUBLIC_ANALYTICS_ID)
taesungh commented 10 months ago

Actually, NEXT_PUBLIC_VERCEL_URL is available

Prefixed Environment Variables will be available during the Build Step (System Environment Variables Overview: Framework Environment Variables).

We should be able to switch to just VERCEL_URL since this environment variable is not needed by the browser.