Skip to content
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

Svelte 5: Should prop fallbacks based on other props be reactive? #12337

Closed
brunnerh opened this issue Jul 7, 2024 · 2 comments
Closed

Svelte 5: Should prop fallbacks based on other props be reactive? #12337

brunnerh opened this issue Jul 7, 2024 · 2 comments

Comments

@brunnerh
Copy link
Member

brunnerh commented Jul 7, 2024

Describe the bug

It is possible to define property fallbacks that use other properties like this:

const { a = 1, b = a + 1 } = $props();

The fallback is only evaluated once, so if the property the fallback value is based on changes, there will be no update.

(Workarounds using $derived are possible.)

Reproduction

REPL

Logs

No response

System Info

REPL

Severity

annoyance

@FoHoOV
Copy link
Contributor

FoHoOV commented Jul 8, 2024

I think being explicit (as what the current direction of things are, and I love it), is better. Direct "vanilla" assignments to variables being reactive would kind of break my expectations of svelte-5 reactivity system. thoughts?

@dummdidumm
Copy link
Member

No they shouldn't be reactive. The fallback value is meant as a fixed initializer when something else is undefined. It becoming reactive would be confusing and harder to opt out of, whereas using $derived is easier to reason about and easy to opt-in.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
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

No branches or pull requests

3 participants