Skip to content

dynamic env vars#2050

Closed
robert-inkeep wants to merge 1 commit intomainfrom
next-docker-env-vars
Closed

dynamic env vars#2050
robert-inkeep wants to merge 1 commit intomainfrom
next-docker-env-vars

Conversation

@robert-inkeep
Copy link
Collaborator

@robert-inkeep robert-inkeep commented Feb 17, 2026

In the docker deployment, with a prebuilt nextjs app, need a way for the built nextjs app to use dynamic environment variables.

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2026

⚠️ No Changeset found

Latest commit: 6ee5d8b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 17, 2026

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

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Feb 17, 2026 2:34am
agents-manage-ui Ready Ready Preview, Comment Feb 17, 2026 2:34am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
agents-docs Skipped Skipped Feb 17, 2026 2:34am

Request Review

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

(1) Total Issues | Risk: Low

🟡 Minor (1) 🟡

🟡 1) agents-manage-ui/src/app/layout.tsx Missing changeset for Docker deployment fix

Issue: This PR enables dynamic rendering for Docker deployments, ensuring environment variables in runtimeConfig are evaluated at request time instead of build time. This is a meaningful behavioral fix for self-hosting users that should be documented in release notes.

Why: The agents-manage-ui package is published (not in .changeset/config.json ignore list). Self-hosting users deploying via Docker should see this fix noted in the changelog so they know the issue has been addressed.

Fix: Add a changeset:

pnpm bump patch --pkg agents-manage-ui "Fix Docker deployments to evaluate environment variables at request time instead of build time"

Refs:


💡 APPROVE WITH SUGGESTIONS

Summary: This is a correct and well-targeted fix. The connection() API is the canonical Next.js 14+ approach to opt into dynamic rendering, and the implementation follows documented best practices. The only suggestion is to add a changeset so self-hosting users see this fix in the release notes.


Discarded (1)
Location Issue Reason Discarded
layout.tsx:110-111 Approach validation — connection() is the correct API Not an issue; informational validation that the implementation is correct
Reviewers (3)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
pr-review-devops 2 1 0 0 0 0 1
pr-review-frontend 0 0 0 0 0 0 0
pr-review-standards 0 0 0 0 0 0 0
Total 2 1 0 0 0 0 1

@github-actions github-actions bot deleted a comment from claude bot Feb 17, 2026
@robert-inkeep
Copy link
Collaborator Author

@claude what are the performance implications? it reads from .env, so it's not really dynamic in the sense it can change whenever, only on initial server load

@claude
Copy link
Contributor

claude bot commented Feb 17, 2026

Claude finished @robert-inkeep's task in 43s —— View job


Performance Analysis

You're absolutely right to question this! The performance implications are minimal in your use case. Here's why:

What connection() does

The connection() call forces Next.js to opt into dynamic rendering for this layout, which means:

  • The page is rendered on each request rather than statically at build time
  • This allows the runtimeConfig object (lines 72-108) to be evaluated fresh on each request

Performance Impact

In your Docker deployment context:

  • Negligible overhead - The .env values are read once when the Node.js process starts (not on every request)
  • No database queries or external API calls - The connection() call itself just waits for request headers to be available
  • Memory impact: ~0 - The environment variables are already in process memory
  • CPU impact: Minimal - Just object construction with string assignments

What actually happens:

  1. Container starts → Node.js loads .env into process.env (once)
  2. Each request → connection() ensures dynamic rendering → runtimeConfig object is created from in-memory values
  3. The "dynamic" part only means the values can differ between container deployments, not between requests

Why this approach makes sense

For Docker deployments with prebuilt Next.js apps:

  • Without connection(): Environment variables are baked into the JavaScript bundle at build time
  • With connection(): Environment variables are read from the container's environment at runtime

This allows the same Docker image to be deployed with different configurations (dev/staging/prod) without rebuilding.

Alternative approaches (for comparison)

  1. Build-time substitution - Would require rebuilding the image for each environment (not ideal)
  2. Client-side fetching - Would add actual network overhead and complexity
  3. This PR's approach - Best balance: dynamic per deployment, but static per container lifecycle

Bottom line: The performance cost is essentially the same as constructing a JavaScript object with ~10 properties on each request - completely negligible compared to the flexibility gained for Docker deployments.

@nick-inkeep
Copy link
Collaborator

Correct approach, merging here.

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