Skip to content

test: assert that pages don't embed env when dynamic public env vars are unused - #16306

Merged
elliott-with-the-longest-name-on-github merged 1 commit into
sveltejs:version-3from
Nic-Polumeyv:omit-env-when-unused
Jul 15, 2026
Merged

test: assert that pages don't embed env when dynamic public env vars are unused#16306
elliott-with-the-longest-name-on-github merged 1 commit into
sveltejs:version-3from
Nic-Polumeyv:omit-env-when-unused

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

closes #8946

The follow-up I promised in #16024, a few weeks late. Retargeting it onto version-3 turned it into a test, because the fix I wrote for main is already there. The env embed sits behind the same client.uses_env_dynamic_public check that the $env/dynamic/public branch has used since #11277:

if (client.uses_env_dynamic_public) {
	properties.push(`env: ${load_env_eagerly ? 'null' : devalue.uneval(env.rendered_env)}`);
}

What's left is the regression coverage. On kit 2 with experimental.explicitEnvironmentVariables enabled, every server-rendered page ships an env: {} object the client can never read, since static values are inlined into the generated $app/env/public module as literals. Rich said as much reviewing #15934, "rendered_env is what gets sent from the server to the client. static variables are already in the client".

One assertion added to the existing options-2 prerender test, so version-3 can't regress into shipping the dead object again. Verified it passes on version-3 and that the same assertion fails on main without the omitted fix.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 10, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 7850e95:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/7850e95ced127a4eab43a2d15228e3a2a9f5d1c9

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16306

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7850e95

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

@teemingc

Copy link
Copy Markdown
Member

Can you please rebase all of your PRs onto the version-3 branch? We have stopped developing against the main branch as we're trying to get SvelteKit 3's release out soon

@Nic-Polumeyv

Copy link
Copy Markdown
Contributor Author

Not a problem with some AI help, sorry for this! Thanks for the heads up.

@Nic-Polumeyv
Nic-Polumeyv changed the base branch from main to version-3 July 15, 2026 01:07
@Nic-Polumeyv
Nic-Polumeyv force-pushed the omit-env-when-unused branch from f2d2ddd to 7850e95 Compare July 15, 2026 01:07
@Nic-Polumeyv Nic-Polumeyv changed the title fix: omit env from server-rendered pages when the client doesn't use dynamic public env vars test: assert that pages don't embed env when dynamic public env vars are unused Jul 15, 2026
@Nic-Polumeyv

Copy link
Copy Markdown
Contributor Author

Heads up on why the diff shrank: version-3 already has this fix. a524898 put the env embed behind client.uses_env_dynamic_public, and #16024 implemented that flag for explicit env. What was left after rebasing is the regression test, retitled accordingly.

@elliott-with-the-longest-name-on-github
elliott-with-the-longest-name-on-github merged commit 383ccc2 into sveltejs:version-3 Jul 15, 2026
17 of 18 checks passed
@Nic-Polumeyv
Nic-Polumeyv deleted the omit-env-when-unused branch July 30, 2026 22:53
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.

Omit env from server renders if $env/dynamic/public isn't used

3 participants