Skip to content

Conversation

@ndhoule
Copy link
Contributor

@ndhoule ndhoule commented Aug 26, 2025

This changeset fixes environment-variable loading a Preview Server context.

Previously, we were missing dev-server from the CLI's list of
supported contexts. Because of a variable that (unnecessarily) mixes the
concept of branches and contexts, when we run into an unsupported
context, we assume we must be running a branch preview, and try to find
variables for the branch named dev-server. For the majority of users,
variables for that branch won't exist, and they'll end up with an
unexpectedly empty variable.

Why do we assume it's a branch preview when we have enough information
available to us to know it's not one? Why do we throw away the type
information that would have caught this? Why do we load environment
variables from the API in the CLI even though @netlify/config already
does this?

These are the mysteries of the universe.

@ndhoule ndhoule requested a review from a team as a code owner August 26, 2025 21:14
@github-actions
Copy link

github-actions bot commented Aug 26, 2025

📊 Benchmark results

Comparing with 99a2f05

  • Dependency count: 1,076 (no change)
  • Package size: 297 MB (no change)
  • Number of ts-expect-error directives: 382 (no change)

@ndhoule ndhoule force-pushed the nathanhoule/ex-387-environment-variables-not-available-to-edge-functions-in branch from 5969270 to f145479 Compare August 26, 2025 21:59
ndhoule added a commit to netlify/primitives that referenced this pull request Aug 26, 2025
@ndhoule ndhoule force-pushed the nathanhoule/ex-387-environment-variables-not-available-to-edge-functions-in branch 3 times, most recently from ff6a7d6 to bc14e8e Compare August 26, 2025 22:31
env[BLOBS_CONTEXT_VARIABLE] = { sources: ['internal'], value: encodeBlobsContext(blobsContext) }

if (!options.offline && !options.offlineEnv) {
if (!(options.offline || options.offlineEnv)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

well, I find first to easier to read, no?

Copy link
Contributor Author

@ndhoule ndhoule Aug 26, 2025

Choose a reason for hiding this comment

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

A matter of taste, but I find "if neither one is true" to be easier to reason about than "if not x and not y." (Fewer logical operations to hold in your head, too.)

@ndhoule ndhoule force-pushed the nathanhoule/ex-387-environment-variables-not-available-to-edge-functions-in branch from 594a391 to b02d96f Compare August 26, 2025 23:01
@ndhoule ndhoule enabled auto-merge (rebase) August 26, 2025 23:03
ndhoule added a commit to netlify/primitives that referenced this pull request Aug 27, 2025
This changeset fixes environment-variable loading a Preview Server context.

Previously, we were missing `dev-server` from the CLI's list of
supported contexts. Because of a variable that (unnecessarily) mixes the
concept of branches and contexts, when we run into an unsupported
context, we assume we must be running a branch preview, and try to find
variables for the branch named `dev-server`. For the majority of users,
variables for that branch won't exist, and they'll end up with an
unexpectedly empty variable.

Why do we assume it's a branch preview when we have enough information
available to us to know it's not one? Why do we throw away the type
information that would have caught this? Why do we load environment
variables from the API in the CLI even though `@netlify/config` already
does this?

These are the mysteries of the universe.
@ndhoule ndhoule force-pushed the nathanhoule/ex-387-environment-variables-not-available-to-edge-functions-in branch from b02d96f to bad236b Compare August 27, 2025 15:30
ndhoule added a commit to netlify/primitives that referenced this pull request Aug 27, 2025
@ndhoule ndhoule merged commit 96ab785 into main Aug 27, 2025
72 of 74 checks passed
@ndhoule ndhoule deleted the nathanhoule/ex-387-environment-variables-not-available-to-edge-functions-in branch August 27, 2025 15:59
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.

3 participants