Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/svelte
SDK Version
8.52.1
Framework Version
Svelte v5.19.6
Link to Sentry event
No response
Reproduction Example/SDK Setup
Repro: https://github.com/scottohara/svelte5-withsentryconfig-bug
The issue occurs when the following is true:
- You have a Svelte component that uses runes (e.g.
let now = $state(new Date().toString());
) - The app is build using webpack + svelte-loader
- You wrap the options passed to svelte-loader with
withSentryConfig()
to enable component tracking, e.g.
export default {
mode: "production",
module: {
rules: [
{
test: /\.svelte$/u,
loader: "svelte-loader",
options: withSentryConfig({
compilerOptions: {...}
})
}
]
}
}
Steps to Reproduce
Setup
git clone https://github.com/scottohara/svelte5-withsentryconfig-bug.git
cd svelte5-withsentryconfig-bug
npm install
webpack
Verify working
At this point, open the file dist/index.html
in your browser. You should see a message like:
The time is
<the current date and time>
This confirms that app builds & runs successfully without component tracking.
Enable component tracking
WITH_SENTRY=1 webpack
The WITH_SENTRY=1
environment variable instructs the webpack config to wrap the svelte-loader options in withSentryConfig()
.
Now open (or refresh) the dist/index.html
page in your browser. You should now see a blank page, and in the browser console the following error:
Uncaught Error: https://svelte.dev/e/lifecycle_legacy_only
When caught, the error message is in fact:
beforeUpdate(...)
cannot be used in runes mode
Expected Result
When component tracking is enabled (in the example repo, by passing WITH_SENTRY=1
to the webpack command; the app should not error and should display the same as when component tracking is disabled.
Actual Result
With component tracking disabled
A successful render, and no console errors:
With component tracking enabled
A failed render (blank page), and the Svelte legacy error:
Why does this happen?
I believe that the root cause is the code in @sentry/svelte
that does component tracking uses the beforeUpdate(...)
lifecycle method.
This lifecycle method is deprecated in Svelte 5.
It may be the case that withSentryConfig()
was never designed to be used with webpack + svelte-loader (as it doesn't seem to have any issues when used in a Vite-based Svelte5 project).
However prior to Svelte 5 and runes mode, using withSentryConfig
in webpack + svelte-loader in this way did not throw any errors.
Metadata
Metadata
Assignees
Type
Projects
Status