-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the bug
Given a parent:
<Child {value} />And a child that can mutate its value prop:
<script>
let {value} = $props()
$inspect(value)
</script>
<input bind:value />Updating the value in the child will skip $inspect but will properly update value (see reproduction)
The documentation reads
Props cannot be mutated, unless the parent component uses bind:. During development, attempts to mutate props will result in an error.
The behavior described above is not raising an error during development. However, I believe this should be enforced at compile time. Mutations have always created undefined behaviors in Svelte (mutations are always possible but not reactive) and it should be possible to solve it in Svelte 5 by forcing either immutability or bindings:
<script>
const {size} = $props() // Cannot use `let` to declare props
let {value} = $binds() // New rune idea
</script>
<input bind:value {size} />Writing <Child {value} {size} /> would cause a "value must be bound" error
In the case of objects, I guess we could step a bit away from usual js where props are always mutable:
const { obj } = $props()
// This would work in js but should not compile in svelte
obj.prop = 1
// Compile error: cannot update `obj` as it is a constant propReproduction
Logs
No response
System Info
svelte 5-rc.26Severity
annoyance
Edit: merry Christmas! 🎅