Skip to content

is it bug? #14803

New issue

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

Closed
mblandr opened this issue Dec 22, 2024 · 2 comments
Closed

is it bug? #14803

mblandr opened this issue Dec 22, 2024 · 2 comments

Comments

@mblandr
Copy link

mblandr commented Dec 22, 2024

Describe the bug

https://svelte.dev/playground/8927c1b4ff6e4905a459fb4045fecdeb?version=5.15.0
why clicking on update value #1 don't update in template?

Reproduction

https://svelte.dev/playground/8927c1b4ff6e4905a459fb4045fecdeb?version=5.15.0

Logs

No response

System Info

repl

Severity

annoyance

@brunnerh
Copy link
Member

brunnerh commented Dec 22, 2024

is it bug?

Not exactly, it was previously decided to not handle this.

Objects that are not primitives should generally not be used like this. You are causing an implicit string conversion which the compiler will ignore for non-state variables. Instead of treating every value in the template as potentially dynamic, only property accesses and function calls will add an effect.

Usually the implicit string conversion of objects is fairly useless anyway (e.g. with dates it outputs a very verbose representation and for arrays there are no spaces between elements). If you want this to happen and dynamically update anyway, you can explicitly convert the value:

- <p>value #1: {newValue}</p>
+ <p>value #1: {newValue.toString()}</p>

Playground

You can also make the variable be considered stateful, e.g.:

- let { value: newValue } = value;
+ let { value: newValue } = $derived(value);

Playground
(Of course this will update the variable in case the $derived is triggered.)

@mblandr
Copy link
Author

mblandr commented Dec 22, 2024

Thanks, I understood

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants