Skip to content

fix(sveltekit): Read SvelteKit config from the Vite plugin - #23678

Draft
chargome wants to merge 3 commits into
developfrom
fix/sveltekit-3-kit-config
Draft

fix(sveltekit): Read SvelteKit config from the Vite plugin#23678
chargome wants to merge 3 commits into
developfrom
fix/sveltekit-3-kit-config

Conversation

@chargome

@chargome chargome commented Aug 27, 2026

Copy link
Copy Markdown
Member

SvelteKit 3 removed svelte.config.js (adapter, files and outDir now go to the sveltekit() Vite plugin), and SvelteKit 2.66+ lets users move their config there too. The SDK still imported svelte.config.js, so those setups silently fell back to defaults, breaking source map upload paths and rewriteFrames for custom adapter out, outDir or hooks paths.

The config now comes from the SvelteKit Vite plugin's api.options, normalized across both majors. svelte.config.js stays as the fallback — SvelteKit only exposes api.options from 2.62 on, so older 2.x apps still resolve through the file.

Why not @sveltejs/load-config? : it re-resolves the vite.config.js we're being constructed by, so it
waits on itself and hangs (verified on Vite 8) — and it reads this same api.options anyway.

SvelteKit 3 removed `svelte.config.js` (adapter, `files` and `outDir` now go to the `sveltekit()`
Vite plugin), and SvelteKit 2.66+ lets users move their config there too. The SDK still imported
`svelte.config.js`, so those setups silently fell back to defaults - breaking source map upload
paths and `rewriteFrames` for custom adapter `out`, `outDir` or hooks paths.

Read the config from the SvelteKit Vite plugin's `api.options` instead, normalized across both
majors. `svelte.config.js` stays as the fallback - SvelteKit only exposes `api.options` from 2.62
on, so older 2.x apps still resolve through the file.

Not `@sveltejs/load-config`: it re-resolves the `vite.config.js` we're being constructed by, so it
waits on itself and hangs - and it reads this same `api.options` anyway.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chargome chargome self-assigned this Aug 27, 2026
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

Comment thread packages/sveltekit/src/vite/sourceMaps.ts
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 28.56 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.75 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.76 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.68 kB - -
@sentry/browser (incl. Tracing, Replay) 88.23 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.63 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.93 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.85 kB - -
@sentry/browser (incl. Feedback) 46.05 kB - -
@sentry/browser (incl. sendFeedback) 33.62 kB - -
@sentry/browser (incl. FeedbackAsync) 38.73 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.3 kB - -
@sentry/react (incl. Tracing) 50.94 kB - -
@sentry/vue 35.73 kB - -
@sentry/vue (incl. Tracing) 51.02 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.35 kB - -
CDN Bundle (incl. Tracing) 49.38 kB - -
CDN Bundle (incl. Logs, Metrics) 32.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.25 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.17 kB - -
CDN Bundle (incl. Tracing, Replay) 86.86 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.8 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.64 kB - -
CDN Bundle - uncompressed 89.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 147.2 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.24 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.89 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.41 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.69 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 286.06 kB - -
@sentry/nextjs (client) 53.56 kB - -
@sentry/sveltekit (client) 49.19 kB - -
@sentry/core/server 65.67 kB - -
@sentry/core/browser 51.86 kB - -
@sentry/node 123.52 kB +0.02% +19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.23 kB - -
@sentry/node - without tracing 87.78 kB +0.03% +22 B 🔺
@sentry/node - without channel injection 103.18 kB +0.03% +22 B 🔺
@sentry/aws-serverless 96.12 kB +0.03% +25 B 🔺
@sentry/cloudflare (withSentry) - minified 201.04 kB - -
@sentry/cloudflare (withSentry) 500.26 kB - -

View base workflow run

`sveltekit()` is an async factory in both SvelteKit majors, so the plugins array Vite passes to
`config` hooks still holds an unresolved promise where the SvelteKit plugin will be - the config
is only findable in `configResolved`. Awaiting it from the source maps plugin's `config` hook
blocked the very phase that would resolve it, hanging `vite build` whenever source map upload was
enabled (the default).

Record the user's `build.sourcemap` setting in `config` (it has to be read before our own source
map settings plugin overwrites it) and resolve the adapter output dir in `configResolved`, which
is still early enough to run the adapter before the build writes anything.

The e2e apps all disable source map upload, so nothing exercised this path; the Vite integration
test now uses an async SvelteKit factory with uploads enabled, and hangs without this fix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2fd3d9e. Configure here.

`process_config()` resolves `outDir` and `files.hooks.*` against the cwd before
SvelteKit exposes them on the Vite plugin's `api.options`, so reading the config
from there handed us absolute paths where `svelte.config.js` gave relative ones.

That broke two things: the hooks file regexp gained a leading `//` and stopped
matching any Vite module id, so the global values were no longer injected into
`hooks.server.*` at all; and `__sentry_sveltekit_output_dir` became a build
machine path that `rewriteFrames` can't match at runtime anywhere else.

Normalizing in `normalizeKitConfig()` covers both sources and also drops the
platform separator, which would have broken the same matching on Windows.

Also settle the config promise in a `finally` so a throwing `configResolved`
can't leave the build hanging on `get()` with no error.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8qBB5MAGR4KYNfMWJcuCF
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.

1 participant