Skip to content

chore(deps): update @sveltejs/vite-plugin-svelte to v7#16549

Merged
ematipico merged 3 commits into
withastro:nextfrom
ocavue-forks:ocavue-sv-vite8
May 20, 2026
Merged

chore(deps): update @sveltejs/vite-plugin-svelte to v7#16549
ematipico merged 3 commits into
withastro:nextfrom
ocavue-forks:ocavue-sv-vite8

Conversation

@ocavue
Copy link
Copy Markdown
Contributor

@ocavue ocavue commented May 1, 2026

AI Disclosure: The code and this description were drafted by Claude and reviewed by me (@ocavue).


Bumps the @sveltejs/vite-plugin-svelte dependency of @astrojs/svelte from v6 to v7.

Why this is more than a version bump

vite-plugin-svelte v7's optimizer now pre-bundles Svelte's SSR runtime (svelte/server, svelte/internal/server) into optimizeDeps for server environments (packages/vite-plugin-svelte/src/plugins/setup-optimizer.js). Astro's renderer entrypoint (@astrojs/svelte/server.js) is resolved as a noExternal dependency, so it keeps the raw transformed copy of that runtime while the user's compiled components get the pre-bundled copy. Two copies means two ssr_context module states — Svelte's dev-only push_element then reads a null context and dev SSR crashes.

It is dev-only (optimizeDeps and push_element are both dev-only), so the build kept passing and the regression was easy to miss.

Fix

A small enforce: 'pre' Vite plugin excludes svelte from optimizeDeps for server environments (packages/integrations/svelte/src/index.ts), so vite-plugin-svelte skips the pre-bundle and the renderer and the components share one transformed copy.

The integration's old optimizeDeps overrides are dropped as redundant:

  • optimizeDeps.include of the Svelte SSR runtime — vite-plugin-svelte v7 does this itself (and it is what causes the bug above).
  • optimize-esbuild-plugins.tsvite-plugin-svelte v7 registers its own .svelte optimizer plugins (packages/vite-plugin-svelte/src/plugins/setup-optimizer.js).

The crawlFrameworkPkgs + resolve.noExternal is kept: it noExternals Svelte component libraries that declare a svelte peer dependency but no svelte export condition, which vite-plugin-svelte treats as "semi-framework" packages and does not noExternal (packages/vite-plugin-svelte/src/utils/options.js).

Testing

  • @astrojs/svelte unit suite — 33 pass, including a dev-server SSR test that fails on vite-plugin-svelte v7 without this fix.
  • @astrojs/cloudflare suite — 215 pass, including a prerender test that renders a Svelte component importing .svelte files from node_modules.
  • Svelte e2e suite — 21 pass (hydration with every client:* directive, HMR, MDX, nested frameworks, slots, lifecycle).

Docs

A changeset file has been added because I want to release this in the next alpha publishing.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 1, 2026

🦋 Changeset detected

Latest commit: 3c0cd6b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@astrojs/svelte Minor
@e2e/errors Patch
@e2e/svelte-component Patch
@e2e/view-transitions Patch
@test/0-css Patch
@test/aliases-tsconfig Patch
@test/aliases Patch
@test/astro-children Patch
@test/astro-client-only Patch
@test/astro-dynamic Patch
@test/astro-slots-nested Patch
@test/component-library Patch
@test/css-dangling-references Patch
@test/fetch Patch
@test/postcss Patch
@test/server-islands-hybrid Patch
@test/server-islands-ssr Patch
@test/slots-svelte Patch
@test/svelte-component Patch
@test/vue-with-multi-renderer Patch
@test/astro-cloudflare-prerender-node-env Patch
@test/astro-cloudflare-svelte-rune-deps Patch
@test/astro-cloudflare-vite-plugin Patch
@test/astro-cloudflare-with-svelte Patch
async-rendering Patch
conditional-rendering Patch
@test/empty-class Patch
svelte-prop-types Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added pkg: svelte Related to Svelte (scope) pkg: integration Related to any renderer integration (scope) labels May 1, 2026
@ocavue ocavue marked this pull request as ready for review May 5, 2026 11:50
@ocavue ocavue force-pushed the ocavue-sv-vite8 branch 2 times, most recently from 73bb876 to 94e8603 Compare May 12, 2026 11:26
@ocavue ocavue marked this pull request as draft May 12, 2026 13:02
@ocavue ocavue force-pushed the ocavue-sv-vite8 branch from 94e8603 to 9866825 Compare May 20, 2026 01:51
@ocavue ocavue force-pushed the ocavue-sv-vite8 branch from d1ddd32 to e06dfe1 Compare May 20, 2026 04:17
@ocavue ocavue marked this pull request as ready for review May 20, 2026 04:36
Comment on lines +32 to +33
// vite-plugin-svelte's classification (pinned to v7.1.2):
// https://github.com/sveltejs/vite-plugin-svelte/blob/471f82216d4459a90d20f21c76b84aaf20c27e6e/packages/vite-plugin-svelte/src/utils/options.js#L478-L513
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.

The explanation makes sense, but adding a link isn't future proof because things can change. Do you need a TODO or FIXME instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

adding a link isn't future proof because things can change

I switched it from a commit SHA to a version tag permalink. Hope the pinned version is explicit and easy to diff if upstream changes later. See commit 3c0cd6b


Do you need a TODO or FIXME instead?

To clarify: do you mean this workaround is temporary and the real fix belongs upstream in vite-plugin-svelte?

If so, I'm not familiar enough with vite-plugin-svelte to tell.

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.

If so, I'm not familiar enough with vite-plugin-svelte to tell.

Neither do I 😆

Comment on lines +72 to +73
// The vite-plugin-svelte code that pre-bundles it (pinned to v7.1.2):
// https://github.com/sveltejs/vite-plugin-svelte/blob/471f82216d4459a90d20f21c76b84aaf20c27e6e/packages/vite-plugin-svelte/src/plugins/setup-optimizer.js#L51-L52
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.

Ditto

@ematipico ematipico merged commit 9d9d516 into withastro:next May 20, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope) pkg: svelte Related to Svelte (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants