Description
Describe the bug
On initial load/SSR, private class fields that use $derived
break with the following:
TypeError: Cannot read properties of undefined (reading '<var name>')
Introduced in [email protected]
Reproduction
<script lang="ts">
class SomeState {
opts: { baz: boolean };
#foo = $derived.by(() => this.opts.baz);
constructor(opts: { baz: boolean }) {
this.opts = opts;
}
}
new SomeState({ baz: true });
</script>
Stackblitz: https://stackblitz.com/github/AdrianGonz97/dependent-on-private-derived-repro?file=README.md
GitHub Repo: https://github.com/AdrianGonz97/dependent-on-private-derived-repro
Logs
System Info
(StackBlitz)
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
svelte: ^5.0.0 => 5.31.1
Severity
blocking an upgrade
Metadata
Metadata
Assignees
Labels
No labels