We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have this code for Box
Box
export class Box<T> { #getter: () => T; #setter?: (value: T) => void; #derived = $derived.by(() => { let val = $state(this.#getter()); return { get current() { return val; }, set current(value) { val = value; } }; }); constructor(getter: () => T, setter?: (value: T) => void) { this.#getter = getter; this.#setter = setter; $effect(() => { this.#setter?.($state.snapshot(this.#derived.current) as T); }); } get current(): T { return this.#derived.current; } set current(value: T) { this.#derived.current = value; } }
Then, I tried to leverage writable $derived and rewrote to this:
export class Box<T> { #getter: () => T; #setter?: (value: T) => void; #derived = $derived.by(() => this.#getter()); constructor(getter: () => T, setter?: (value: T) => void) { this.#getter = getter; this.#setter = setter; $effect(() => { this.#setter?.($state.snapshot(this.#derived) as T); }); } get current(): T { return this.#derived; } set current(value: T) { this.#derived = value; } }
This gave the issue when generated on server
Reason: This is generating the following invalid code when generate: "server":
generate: "server"
class Box { #getter; #setter; #derived = $.once(() => this.#getter()); constructor(getter, setter) { this.#getter = getter; this.#setter = setter; } get current() { return this.#derived(); } set current(value) { this.#derived() = value; } }
The line this.#derived() = value; is wrong.
this.#derived() = value;
https://svelte.dev/playground/hello-world?version=5.25.6#H4sIAAAAAAAAE31SwW6DMAz9FSvrIUgVu9OWajvtA3obO2TgtkhZgmJDO1X8-0yBwdi0KIfk-fk9J_ZNOfOBKlEvaK2Hiw-2AI1FyVhEaq2OpUVSyetN8WfV8TpA8CHrqapiatByh70bwr_w3DtGxyKjtpSHsmKwxp12mWLKVJq5jPFa-cCQW0MEz_66PaRwyxzIejghM4YEdAS7FA6bAaY7vBe8MbbGBA73eOPLQigDqcBQNljADlbDUQOfS4oHVR1F32QpkzjUOfugF55r-MctGivt1lxcXPvDZhmnMU5jfGKs8HjEnHVvPZNepu9jvSI2jDE5U9HZs-7Dw0sjMCRlzszb8dKOhlIf5HUI0h4dyaPmfgG5Dg5-aC7zaZY_fcyv_5jacCdNKrK3j_1MpCCjIoPAKpEuYPsmN1PaS-kKlRyNJWy_ACjOwAGtAgAA
Go to compile settings, turn on generate: server
generate: server
System: OS: macOS 15.4 CPU: (10) arm64 Apple M1 Pro Memory: 97.44 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.14.0 - ~/.volta/tools/image/node/22.14.0/bin/node npm: 10.9.2 - ~/.volta/tools/image/node/22.14.0/bin/npm pnpm: 9.2.0 - ~/.volta/bin/pnpm bun: 1.2.4 - ~/.bun/bin/bun Browsers: Edge: 134.0.3124.95 Safari: 18.4 npmPackages: svelte: 5.25.6 => 5.25.6
annoyance
The text was updated successfully, but these errors were encountered:
We already noticed this during #15628 and marked it as a follow-up, but didn't think about the static-code-generation-side of things. Related #14977
Sorry, something went wrong.
No branches or pull requests
Describe the bug
I have this code for
Box
Then, I tried to leverage writable $derived and rewrote to this:
This gave the issue when generated on server
Reason: This is generating the following invalid code when
generate: "server"
:The line
this.#derived() = value;
is wrong.Reproduction
https://svelte.dev/playground/hello-world?version=5.25.6#H4sIAAAAAAAAE31SwW6DMAz9FSvrIUgVu9OWajvtA3obO2TgtkhZgmJDO1X8-0yBwdi0KIfk-fk9J_ZNOfOBKlEvaK2Hiw-2AI1FyVhEaq2OpUVSyetN8WfV8TpA8CHrqapiatByh70bwr_w3DtGxyKjtpSHsmKwxp12mWLKVJq5jPFa-cCQW0MEz_66PaRwyxzIejghM4YEdAS7FA6bAaY7vBe8MbbGBA73eOPLQigDqcBQNljADlbDUQOfS4oHVR1F32QpkzjUOfugF55r-MctGivt1lxcXPvDZhmnMU5jfGKs8HjEnHVvPZNepu9jvSI2jDE5U9HZs-7Dw0sjMCRlzszb8dKOhlIf5HUI0h4dyaPmfgG5Dg5-aC7zaZY_fcyv_5jacCdNKrK3j_1MpCCjIoPAKpEuYPsmN1PaS-kKlRyNJWy_ACjOwAGtAgAA
Go to compile settings, turn on
generate: server
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: