Skip to content

Fix Netlify runtime env resolution and Vercel Analytics loading#431

Merged
liudmylasovetovs merged 1 commit intodevelopfrom
sl/feat/db-optimization
Mar 29, 2026
Merged

Fix Netlify runtime env resolution and Vercel Analytics loading#431
liudmylasovetovs merged 1 commit intodevelopfrom
sl/feat/db-optimization

Conversation

@LesiaUKR
Copy link
Copy Markdown
Collaborator

@LesiaUKR LesiaUKR commented Mar 29, 2026

Problem

On Netlify SSR/runtime, environment variables were intermittently unavailable in process.env.
Also, Vercel Analytics script was loaded on Netlify and produced 404 errors (/_vercel/insights/script.js).

Changes

  • Updated frontend/lib/env/server-env.ts:
    • keep process.env as primary source
    • add robust Netlify fallback that supports:
      • globalThis.Netlify
      • global Netlify identifier (Netlify.env.get)
  • Updated frontend/app/layout.tsx:
    • changed Analytics condition from NODE_ENV === 'production'
    • to process.env.VERCEL === '1' (load only on Vercel)

Why

  • Improves cross-platform behavior (Vercel + Netlify).
  • Prevents false-negative env reads in Netlify runtime.
  • Removes noisy/incorrect analytics requests on Netlify.

Verification

  • Netlify deploy: no /_vercel/insights/script.js 404 in browser console.
  • Runtime logs include expected env presence when configured.
  • Vercel deploy still renders Analytics as before.

Risk

Low. Changes are isolated to env resolution and analytics rendering condition.

Summary by CodeRabbit

  • Chores
    • Analytics component rendering now uses deployment platform configuration instead of build environment detection.
    • Refactored environment variable handling for Netlify runtime to improve compatibility with different deployment configurations.

… on Netlify

- update server env resolver to read Netlify runtime env safely
  (supports both globalThis.Netlify and global Netlify identifier)
- keep process.env as primary source, Netlify env as fallback
- render @vercel/analytics only on Vercel (VERCEL=1) to avoid Netlify 404s
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
devlovers-net Ignored Ignored Preview Mar 29, 2026 2:56pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be80d3d9-2ad3-44e3-b72e-ffe6c4dca5e9

📥 Commits

Reviewing files that changed from the base of the PR and between 5f84e73 and ee8169d.

📒 Files selected for processing (2)
  • frontend/app/layout.tsx
  • frontend/lib/env/server-env.ts

📝 Walkthrough

Walkthrough

This PR updates the Analytics component rendering condition from checking production environment to checking for Vercel deployment, and refactors Netlify runtime environment access with a new helper function for improved compatibility.

Changes

Cohort / File(s) Summary
Analytics Condition Update
frontend/app/layout.tsx
Changed Analytics component rendering condition from process.env.NODE_ENV === 'production' to process.env.VERCEL === '1', triggering Analytics based on Vercel deployment flag instead of build environment.
Netlify Runtime Helper
frontend/lib/env/server-env.ts
Introduced NetlifyRuntime type and getNetlifyRuntime() helper function to safely access Netlify global runtime. Refactored readFromNetlifyEnv() to use the new helper instead of direct globalThis access, with improved fallback handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • AM1007
  • ViktorSvertoka
  • liudmylasovetovs

Poem

🐰 In Vercel's fields where Analytics play,
We check the flag instead of day,
And Netlify's runtime, safe and sound,
With helper functions all around,
The env vars hop through the code so clean! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the two main changes in the pull request: fixing Netlify runtime environment resolution and fixing Vercel Analytics loading conditions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sl/feat/db-optimization

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@liudmylasovetovs liudmylasovetovs merged commit 1ee6d1e into develop Mar 29, 2026
8 checks passed
@liudmylasovetovs liudmylasovetovs deleted the sl/feat/db-optimization branch March 29, 2026 14:34
@LesiaUKR LesiaUKR restored the sl/feat/db-optimization branch March 29, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants