-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Open
Labels
Milestone
Description
Describe the problem
Svelte 5 warns when non-binded props are mutated which is a very good thing to avoid unexpected side effect.
However, there is no way to tell if a prop is actually binded or not, or at least if there is it doesn't appear to be documented.
Shallow/deep copy could be avoided in some scenarios where performance matter if it's not even used.
Describe the proposed solution
Here is a real life possible scenario where you might just want to call a callback with the new values without mutating the actual passed value.
<!-- MyComponent.svelte -->
<script>
let { values = $bindable(), onChange } = $props();
const addValue = (newValue) => {
if (isBindedProp(values)) {
values ||= [];
values.push(newValue);
onChange?.(values);
} else {
onChange?.([...(values || []), newValue]);
}
};
</script>
....
<!-- Somewhere -->
<MyComponent bind:values={...}>
<!-- Somewhere else -->
<MyComponent values={...} onChange{...}>Importance
must have.
Svelte 4 librairies should be able to tell that as well to preserve compatibility without switching to runes
someone2080 and VityaSchel