Skip to content

chore: move remote plugin - #16868

Merged
teemingc merged 7 commits into
version-3from
chore-remote-plugin
Aug 21, 2026
Merged

teemingc merged 7 commits into
version-3from
chore-remote-plugin

Conversation

@teemingc

Copy link
Copy Markdown
Member

No description provided.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from ff0d737:

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

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

@changeset-bot

changeset-bot Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ff0d737

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

Comment thread packages/kit/src/exports/vite/index.js Resolved
…n `experimental.remoteFunctions` is disabled (the default), causing every production build to crash in `generate_manifest`/`analyse`.

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

## Bug

The "move remote plugin" refactor (`d2aa2c0`) changed the declarations in `packages/kit/src/exports/vite/index.js` from initialized values to bare `let`:

```js
// before
let remotes = [];
const remote_original_by_hash = new Map();

// after
let remotes;               // undefined
let remote_original_by_hash; // undefined
```

These are now only assigned via the `set_remote_metadata` callback passed to `plugin_remote`:

```js
(remote_array, remote_original_map) => {
  remotes = remote_array;
  remote_original_by_hash = remote_original_map;
}
```

`set_remote_metadata` is invoked from exactly one place — `plugin_remote`'s `buildStart` hook (`plugins/remote.js:66`, confirmed by grep). But that plugin gates on:

```js
applyToEnvironment(environment) {
  return svelte_config.experimental.remoteFunctions && environment.name !== 'serviceWorker';
}
```

When `experimental.remoteFunctions` is `false` (the **default**), `applyToEnvironment` returns `false` for every environment, so the plugin is filtered out and its `buildStart` never runs. `set_remote_metadata` is therefore never called and `remotes` / `remote_original_by_hash` stay `undefined` for the whole build.

## Trigger

A standard production build (`vite build`) with the default config (remote functions off). In `buildApp` → `process_ssr_build`, `remotes` is consumed unconditionally:

*   `generate_manifest({ ..., remotes })` → `remotes.map(remote => ...)` at `core/generate_manifest/index.js:118` → **`Cannot read properties of undefined (reading 'map')`**
*   `analyse({ ..., remotes })` → `for (const remote of remotes)` at `core/postbuild/analyse.js:149` → **`undefined is not iterable`**
*   `treeshake_prerendered_remotes(..., remotes, remote_original_by_hash)`

So every default-config production build throws.

## Fix

Restore the prior default initializers in `index.js`:

```js
let remotes = [];
let remote_original_by_hash = new Map();
```

When `remoteFunctions` is enabled, the `set_remote_metadata` callback still overwrites these with the real values during `buildStart`; when disabled, they remain valid empty defaults so the downstream `.map(...)` / `for...of` iterations are no-ops instead of crashing.


Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <[email protected]>
@teemingc
teemingc merged commit 96a5cad into version-3 Aug 21, 2026
40 checks passed
@teemingc
teemingc deleted the chore-remote-plugin branch August 21, 2026 10:23
Nic-Polumeyv added a commit that referenced this pull request Nov 22, 2026
Fixes #17609

Every server-side transform of a remote module appends a record, even
when its filename-derived hash is already known. HMR therefore retains
an additional record on every edit. The lazy dev manifest hides the
duplicates by overwriting object entries, but still traverses the
growing collection on every access.

Store the registry in a Map keyed by the normalized remote hash. Each
transform replaces the current record, making duplicate retention
impossible without scanning existing records. The dev manifest consumes
the live map's values; the compile plugin materializes an array once at
the production boundary, preserving the existing analysis, treeshaking,
and adapter contracts.

The shared discovery mechanism survived the [remote plugin
extraction](#16868) and [compile
plugin separation](#16885). It still
needs to remain live because modules are discovered after the [dev
manifest is initialized](#16965).
Preserve the [watch-mode
reset](#16632), dedicated entry
emission, original-module lookup, self-import protection, and dev source
decoration. Registration continues using the query-normalized identity
from [#17604](#17604).

A linear push guard would prevent retention but scan all known remotes
on each transform; deduplicating only the manifest would leave the
memory growth intact. The regression instead inspects the underlying
registry through a real Vite server, covering lazy discovery and
repeated transforms that page-content assertions cannot distinguish.

- [Ported minimal
reproduction](https://www.sveltelab.dev/#code=N4IgzgTgxiBcoBMCWECmUAuB7CBPOoAhgA7EB0AFhgLYA2BIAZkrag1FgHYardhwgAPAEIEWTLmKoABFToA%2BADqdBc2tNqFOAcwC8ikLwNLOijKtSEEJs2cHVUGQtKgVCEMI-0gArhkYAtAAcBtIA9DYYdg5O0pyEDt4AbkioAO7EOFEgLlw83N5pSAgYFLoIqClQqAFFJRQANNJInEgYSIS0AWBQnai6AIyhEcq25jHO8YkGPAAeGN29rKEc3LwY3j19w5FmAKRgSai0PADWbZSWCHuj5mEUV5GCAEZYCLjSCIRO3UcnqOcFsQ0LQsFYAl8nN4KFgjhBjLc7MgktIwBhcKxvMgwMRNLhYLk1nxjAc-mcLq93ntBGFkU8wpTcCYaWoTCAAL7shogCBYPyofjwEDINCYHD4IUARx8qDwAQ41GoWgQZDQ1CwPDIACtBaBmKx2Hl1oKQEhqJkIBhpMBpNLZR92dJGLzqNIAOQAEhIxDCnggcLdAG5RpxULMLVbVmjZMdQdJdLaZXgABTJgCU8fk7oAErGsNI1RrUG608HOByuSAANR4vkYMiHY48Bj6thC1b5DAmwQ9CBIYgYSKsK021wsBBoTjSR0Jj3ArDEMDpss03v9wch4AAAUnFQgLgo48n6fZygr3KrxEI2lQDbJbb1LAfIA7xoEPagfYHkTNEetMdoONHWdLBXTdMgwjtOUFSVTgVULTUdSDZRV0-ddmQoAZ5GAQg0kINoANBE8WSwlDiHkABBUheAQXJFWNaRsETe15VA2D4NQdVELAaRlQLY4wRVaQABVZWoFpOkYjVJNFHAEB47ReTSMBA0%2BJA0RaTBZEIMAHh4tFCFwHjvmkAYyGaTg0QgHwHG4bVjIQeS1OvTgsA0qANCwbRtBabQLOkBx1TwaRkwAOTeGQACZIrIAYAFYqzTMgaXIs9OXSysrygU5r1vHUuBbJ9DSJLsBGAZRpGkAwplQAwCQMQEAgGAB2AA2AAGABOAwGgqqqQGBJAkm%2BWq4EY6zUF6qd%2BrhMAkC4Or%2BvashlqGEApsqmZJFG%2BqQHVBAfGWda%2BoMNcBzARbyumzbhUqRbqoi6QAgCX8smkCCWismz1nsuIIoAfX2w6BTCFIeAZFpQbaPKeIqJIer6m7nh8cd7pAMGZGR1GQD6rkTtupIABFUCkODeCgVILrGq7KpurdG3%2BHUwkBNGAGZYtihHrv6%2Bn7yZjGAlxHwfM4X4mx2-rmrIGL2q52n%2BoZng0bisg4qlyK5dpgwMbRoIyHZ2Wmcem09OHZc90ehshVmYbQyFKoVW2KzsTVey1-0VgECOAl13V58WmcBKGeGQ1pzTem0KmYUMAGEuBt6cnR9t0MZD5Qwz-SPCEOq1I5aVBY84G3kyuswhZFsACQAbQ9wFi8ROYpD7WynFoAkbQQ1AADEfE4TB5ssgkMAm6cprGBViCfCAAHkB37iv-3T2UzXWTo294sBcF7wfh8dE2zHZNMAF1lAPstzc%2BofvrsnVCoNdsjT4ARXZHfifLRWVsywLBTh473QPdVyFRYBA1YCHNAb8eAQE-t-JcJcMCgisMmHwEBaBNFfPMJooZ5gZjgWYKMVo0BgGzvGOIYYMBIJQWgo02CyxjCQIwEKyDaBkBomAAA6m0CgyY3RB1QGEMun0wgd3siWHB9czCEOzg2Pk0AZAJgAMpD18smSRJxpHIOqElNAuJCDVG4R3MAZBiA%2BF0ioziRZSxuiaAAAwMUYkxXCO6lmUFGLArAyCgm0GYriAoPG8G0KUTB6RpDyMcN4oshilTEBUZmAslAdIUDTElOaAAvSazQEClmsc40wUQMB7zyWgDAyCpyqIwLQ-JJ8GckVnZEAA)

<!--
svelte-triage-bot:feedback-baseline:4ce7989bbcc4cd6195f371674a76f4280c937f3b
-->

---------

Co-authored-by: svelte-triage-bot <[email protected]>
Co-authored-by: Nic Polumeyv <[email protected]>
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