Skip to content

Add fine-grained environment variable injection control#547

Draft
Copilot wants to merge 8 commits intomainfrom
copilot/add-env-var-injection-option
Draft

Add fine-grained environment variable injection control#547
Copilot wants to merge 8 commits intomainfrom
copilot/add-env-var-injection-option

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 27, 2025

  • Explore repository structure and understand current env var implementation
  • Add injectUserEnv option to Features interface
  • Update NetlifyDev to handle the new option
  • Update environment variable injection logic to conditionally inject user-defined env vars
  • Fix and validate tests for the new fine-grained env var injection
  • Run tests and validate changes
  • Address code review feedback (extract helper function, fix indentation)
  • Update documentation in README files
  • Security scan with CodeQL (no vulnerabilities found)
  • Final documentation improvements
  • Fix formatting and linting issues

Summary

Fixed formatting issues identified by prettier:

  • Removed trailing whitespace in test files
  • Adjusted line wrapping in README to meet formatting standards

All changes are cosmetic whitespace fixes that don't affect functionality.

Original prompt

Issue Title: Add fine-grained env var injection to Vite plugin and Astro adapter
Issue Description: Astro’s Netlify adapter disables the Vite plugin’s environment variables feature by default, which prevents basic platform vars (e.g., NETLIFY_LOCAL, CONTEXT, SITE_ID) from being available in local dev. This led to differences vs. netlify dev (e.g., purgeCache() failing without a site ID when using the Vite plugin).

Proposal:

  • Add a more granular option to the Vite plugin, e.g. features.environmentVariables.injectUserEnv: boolean, so platform env vars can be enabled without injecting user-defined env.
  • Update the Astro Netlify adapter to use this option so platform vars are available by default while user env remains off if desired.

References:

Comment by User db2967f5-c49c-428b-ae14-6c61855027c1:
netlify/primitives

Comment by User c8ba5c18-8b2b-41c2-8484-9ca4ad793475:
📋 I wasn't able to determine which GitHub repository to work in.

I think it's one of these, but can you tell me which one is right?

Comment by User c8ba5c18-8b2b-41c2-8484-9ca4ad793475:
📋 I wasn't able to determine which GitHub repository to work in.

I think it's one of these, but can you tell me which one is right?

Comment by User :
This thread is for an agent session with githubcopilot.

Comment by User :
This thread is for an agent session with githubcopilot.

Comment by User 8e14cbd8-ca68-4b55-956a-3ba8677986e0:
Seems like they preferred to release after ensuring the prompt is good, rather than releasing garbage quickly 😉

Comment by User 8e14cbd8-ca68-4b55-956a-3ba8677986e0:
Nice!

Comment by User db2967f5-c49c-428b-ae14-6c61855027c1:
Wow I'm impressed. That Linear issue description is perfect.

Comment by User :
Created issue FRB-2020

Comment by User db2967f5-c49c-428b-ae14-6c61855027c1:
This comment thread is synced to a corresponding thread in Slack. All replies are displayed in both locations.

Comment by User 8e14cbd8-ca68-4b55-956a-3ba8677986e0:
Meanwhile, merged updates https://github.com/netlify-templates/astro-platform-starter

Comment by User db2967f5-c49c-428b-ae14-6c61855027c1:
let me try this new fancy thing...
@linear create an issue to add the more fine-grained env var option I mentioned above to the vite plugin + update the astro netlify adapter to use it

Comment by User 8e14cbd8-ca68-4b55-956a-3ba8677986e0:
But seems like the scope of not enabling it is a bit wider than we thought, or we'd have taken care of the "platform" env vars then

Comment by User 8e14cbd8-ca68-4b55-956a-3ba8677986e0:
Yeah, I recall that we talked to @matthew Phillips about that

Comment by User db2967f5-c49c-428b-ae14-6c61855027c1:
trying to remember what astro was even trying to solve by disable env vars... found the PR that did it: withastro/astro#14078. :confused-travolta:

Seems like it was just about the surprise factor / potentially breaking change:

First, the Vite plugin was injecting env vars from linked Netlify sites. This is nice DX, but is a change that could surprise peopel - suddenly their dev environment had variables they weren't expecting, which could mess with their local setup.

Comment by User 8e14cbd8-ca68-4b55-956a-3ba8677986e0:
anyway this solves the purgeCache() failure, but I was curious if I would get AI Gateway env vars as well, and the answer's still no 😕

Comment by User 8e14cbd8-ca68-4b55-956a-3ba8677986e0:
I agree, we should bring that up since our own platform functionality is impaired

Comment by User db2967f5-c49c-428b-ae14-6c61855027c1:
btw arguably the @astrojs/netlify docs are lying here (they say the env vars feature is enabled, then lower on the page it says disabled): [https://docs.astro.build/en/guides/integrations-guide/netlify/#local-development-features](https://docs.astro.build/en/guides/integrations-guide/netlify/#local-development...


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 27, 2025 15:38
Co-authored-by: serhalp <1377702+serhalp@users.noreply.github.com>
Co-authored-by: serhalp <1377702+serhalp@users.noreply.github.com>
Co-authored-by: serhalp <1377702+serhalp@users.noreply.github.com>
Co-authored-by: serhalp <1377702+serhalp@users.noreply.github.com>
Copilot AI changed the title [WIP] Add fine-grained env var injection to Vite plugin and Astro adapter Add fine-grained environment variable injection control Nov 27, 2025
Copilot AI requested a review from serhalp November 27, 2025 15:52
Copy link
Copy Markdown
Member

@serhalp serhalp left a comment

Choose a reason for hiding this comment

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

LGTM

@serhalp
Copy link
Copy Markdown
Member

serhalp commented Feb 12, 2026

@copilot fix formatting and linting

Co-authored-by: serhalp <1377702+serhalp@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 12, 2026

@copilot fix formatting and linting

Fixed formatting issues in commit 9b1bcaa. Changes include:

  • Removed trailing whitespace in test files
  • Adjusted line wrapping in README to meet prettier standards

Copilot AI requested a review from serhalp February 12, 2026 14:02
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