Skip to content

Commit 77bd52e

Browse files
committed
docs: explain prop update breaking change
1 parent 7e9b109 commit 77bd52e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

sites/svelte-5-preview/src/routes/docs/content/03-appendix/02-breaking-changes.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,33 @@ In Svelte 4 syntax, every property (declared via `export let`) is bindable, mean
133133

134134
Setting the `accessors` option to `true` makes properties of a component directly accessible on the component instance. In runes mode, properties are never accessible on the component instance. You can use component exports instead if you need to expose them.
135135

136+
### Props may update when value is unchanged
137+
138+
In Svelte 4, components would check whether their props had changed. For example, in this situation...
139+
140+
```svelte
141+
<script>
142+
import Marker from './Marker.svelte';
143+
144+
let coords = { x: 0, y: 0 };
145+
146+
function onclick(e) {
147+
coords = { x: e.clientX, y: e.clientY };
148+
}
149+
</script>
150+
151+
<svelte:window on:click={onclick} />
152+
153+
<button on:click={update}>update</button>
154+
<Marker x={coords.x} y={coords.y} />
155+
```
156+
157+
...clicking twice in the same spot wouldn't cause anything inside `Marker.svelte` to react to the second click, because from its perspective `x` and `y` are unchanged.
158+
159+
Svelte 5 uses fine-grained reactivity, and as such this check no longer happens. Most of the time this results in fewer updates because Svelte no longer needs to conservatively assume that non-primitive values changed. In this case, however, reassigning `coords` _will_ cause updates even if `coords.x` and `coords.y` are unchanged.
160+
161+
For more complex props (namely, those involving function calls) the parent component will memoize the value.
162+
136163
## Other breaking changes
137164

138165
### Stricter `@const` assignment validation

0 commit comments

Comments
 (0)