Skip to content

chore: remove define merging - #16819

Draft
Rich-Harris wants to merge 7 commits into
version-3from
generated-alias-remove-define-merging
Draft

chore: remove define merging#16819
Rich-Harris wants to merge 7 commits into
version-3from
generated-alias-remove-define-merging

Conversation

@Rich-Harris

Copy link
Copy Markdown
Member

follow-up to #16812 — just curious to see what breaks if we remove this

Rich-Harris and others added 6 commits August 14, 2026 21:22
…odule path, so it never matches and is always `false`.

This commit fixes the issue reported at packages/kit/src/exports/vite/index.js:1773

## Bug

In `packages/kit/src/exports/vite/plugins/env-vars.js`, this PR moved the generated env directory:

```js
dir = posixify(
  path.resolve(c.root, config.outDir, `generated/${is_build ? 'build' : 'dev'}/env`)
);
```

So in build mode the client env module is written to `${out_dir}/generated/build/env/public/client.js`.

But `packages/kit/src/exports/vite/index.js:1773` still looked up the pre-PR path:

```js
chunk.modules[`${out_dir}/generated/env/public/client.js`]
```

`chunk.modules` keys are absolute module paths, and `out_dir === posixify(kit.outDir)` matches the base env-vars.js resolves against — so the only difference is the missing `build/` segment. This block runs during the client build (`is_build` is always true here, consistent with line 461 which uses `generated/${is_build ? 'build' : 'dev'}`), so the lookup can never match.

## Impact

`uses_env_dynamic_public` becomes stuck at `false`. It is stored in `build_data.client` (lines ~1801 and ~1849) and controls whether the runtime prerendered public env module is loaded at runtime. Apps that import `$app/env/public` on the client **and** use dynamic (non-static) public env vars would silently get stale/missing runtime env values — a regression versus before this PR, where the path matched.

## Trigger

Build an app that imports `$app/env/public` in client code with at least one `public && !static` env var configured. Previously the chunk-module lookup matched and `uses_env_dynamic_public` was `true`; now it always resolves `false`.

## Fix

Updated the lookup to the new build-mode path:

```js
chunk.modules[`${out_dir}/generated/build/env/public/client.js`]
```


Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <hello@rich-harris.dev>
@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 15, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 4c24254:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/4c242541e990d32758890ae82ba926a7524d8509

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

@changeset-bot

changeset-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4c24254

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

@svelte-docs-bot

Copy link
Copy Markdown

@Rich-Harris

Copy link
Copy Markdown
Member Author

@teemingc can you remember why this was necessary? it was introduced in #16632

@Rich-Harris

Copy link
Copy Markdown
Member Author

Oh actually I tell a lie, it predates that — the git blame is confusing because the structure changed slightly

Base automatically changed from generated-alias to version-3 August 17, 2026 22:23
Comment on lines 1978 to 1980
builder.environments.serviceWorker.config.resolve.alias = [
...get_config_aliases(kit, vite_config.root)
];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
builder.environments.serviceWorker.config.resolve.alias = [
...get_config_aliases(kit, vite_config.root)
];

We ought to get rid of this too. It was only there to avoid resolving the __SERVER__ alias but we now use this setting for much more than that. Ideally, we'd still remove __SERVER__ somehow but maybe it doesn't matter?

@teemingc teemingc Aug 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here's what the service worker allows resolving to if not overridden:

[
  {
    find: '__SERVER__',
  },
  {
    find: '$app',
  },
  {
    find: '$env',
  },
  {
    find: '<sveltekit:generated>',
  },
  {
    find: '__sveltekit/server',
  },
  {
    find: /^\/?@vite\/env/,
  },
  {
    find: /^\/?@vite\/client/,
  }
]

@Rich-Harris
Rich-Harris marked this pull request as draft August 18, 2026 14:38
@Rich-Harris

Copy link
Copy Markdown
Member Author

Marking this draft as it'll conflict with #16813. We need to add some defines to the service worker environment so that it can correctly build $app/manifest. Will update that PR so that it only adds those, rather than also mirroring all the client stuff

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