Skip to content

Commit 865ac6d

Browse files
committed
Merge remote-tracking branch 'upstream/main' into structuredclone-patch
2 parents ebab40a + bbf3829 commit 865ac6d

File tree

328 files changed

+7982
-11846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

328 files changed

+7982
-11846
lines changed

documentation/docs/02-runes/07-$inspect.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,20 @@ A convenient way to find the origin of some change is to pass `console.trace` to
4242
// @errors: 2304
4343
$inspect(stuff).with(console.trace);
4444
```
45+
46+
## $inspect.trace(...)
47+
48+
This rune, added in 5.14, causes the surrounding function to be _traced_ in development. Any time the function re-runs as part of an [effect]($effect) or a [derived]($derived), information will be printed to the console about which pieces of reactive state caused the effect to fire.
49+
50+
```svelte
51+
<script>
52+
import { doSomeWork } from './elsewhere';
53+
54+
$effect(() => {
55+
+++$inspect.trace();+++
56+
doSomeWork();
57+
});
58+
</script>
59+
```
60+
61+
`$inspect.trace` takes an optional first argument which will be used as the label.

documentation/docs/03-template-syntax/03-each.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ Iterating over values can be done with an each block. The values in question can
2323
</ul>
2424
```
2525

26-
You can use each blocks to iterate over any array or array-like value — that is, any object with a `length` property.
27-
2826
An each block can also specify an _index_, equivalent to the second argument in an `array.map(...)` callback:
2927

3028
```svelte

documentation/docs/03-template-syntax/06-snippet.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Snippets can reference themselves and each other ([demo](/playground/untitled#H4
112112

113113
## Passing snippets to components
114114

115-
Within the template, snippets are values just like any other. As such, they can be passed to components as props ([demo](/playground/untitled#H4sIAAAAAAAAE41SwY6bMBD9lRGplKQlYRMpF5ZF7T_0ttmDwSZYJbZrT9pGlv-9g4Fkk-xhxYV5vHlvhjc-aWQnXJK_-kSxo0jy5IcxSZrg2fSF-yM6FFQ7fbJ1jxSuttJguVd7lEejLcJPVnUCGquPMF9nsVoPjfNnohGx1sohMU4SHbzAa4_t0UNvmcOcGUNDzFP4jeccdikYK2v6sIWQ3lErpui5cDdPF_LmkVy3wlp5Vd5e2U_rHYSe_kYjFtl1KeVnTkljBEIrGBd2sYy8AtsyLlBk9DYhJHtTR_UbBDWybkR8NkqHWyOr_y74ZMNLz9f9AoG6ePkOJLMHLBp-xISvcPf11r0YUuMM2Ysfkgngh5XphUYKkJWU_FFz2UjBkxztSYT0cihR4LOn0tGaPrql439N-7Uh0Dl8MVYbt1jeJ1Fg7xDb_Uw2Y18YQqZ_S2U5FH1pS__dCkWMa3C0uR0pfQRTg89kE4bLLLDS_Dxy_Eywuo1TAnPAw4fqY1rvtH3W9w35ZZMgvU3jq8LhedwkguCHRhT_cMU6eVA5dKLB5wGutCWjlTOslupAxxrxceKoD2hzhe2qbmXHF1v1bbOcNCtW_zpYfVI8h5kQ4qY3mueHTlesW2C7TOEO4hcdwzgf3Nc7cZxUKKC4yuNhvIX_MlV_Xk0EAAA=)):
115+
Within the template, snippets are values just like any other. As such, they can be passed to components as props ([demo](/playground/untitled#H4sIAAAAAAAAE3VS247aMBD9lZGpBGwDASRegonaPvQL2qdlH5zYEKvBNvbQLbL875VzAcKyj3PmzJnLGU8UOwqSkd8KJdaCk4TsZS0cyV49wYuJuQiQpGd-N2bu_ooaI1YwJ57hpVYoFDqSEepKKw3mO7VDeTTaIvxiRS1gb_URxvO0ibrS8WanIrHUyiHs7Vmigy28RmyHHmKvDMbMmFq4cQInvGSwTsBYWYoMVhCSB2rBFFPsyl0uruTlR3JZCWvlTXl1Yy_mawiR_rbZKZrellJ-5JQ0RiBUgnFhJ9OGR7HKmwVoilXeIye8DOJGfYCgRlZ3iE876TBsZPX7hPdteO75PC4QaIo8vwNPePmANQ2fMeEFHrLD7rR1jTNkW986E8C3KwfwVr8HSHOSEBT_kGRozyIkn_zQveXDL3rIfPJHtUDwzShJd_Qk3gQCbOGLsdq4yfTRJopRuin3I7nv6kL7ARRjmLdBDG3uv1mhuLA3V2mKtqNEf_oCn8p9aN-WYqH5peP4kWBl1UwJzAEPT9U7K--0fRrrWnPTXpCm1_EVdXjpNmlA8G1hPPyM1fKgMqjFHjctXGjLhZ05w0qpDhksGrybuNEHtJnCalZWsuaTlfq6nPaaBSv_HKw-K57BjzOiVj9ZKQYKzQjZodYFqydYTRN4gPhVzTDO2xnma3HsVWjaLjT8nbfwHy7Q5f2dBAAA)):
116116

117117
```svelte
118118
<script>
@@ -144,7 +144,7 @@ Within the template, snippets are values just like any other. As such, they can
144144

145145
Think about it like passing content instead of data to a component. The concept is similar to slots in web components.
146146

147-
As an authoring convenience, snippets declared directly _inside_ a component implicitly become props _on_ the component ([demo](/playground/untitled#H4sIAAAAAAAAE41Sy27bMBD8lYVcwHYrW4kBXxRFaP-htzgHSqQsojLJkuu2BqF_74qUrfhxCHQRh7MzO9z1SSM74ZL8zSeKHUSSJz-MSdIET2Y4uD-iQ0Fnp4-2HpDC1VYaLHdqh_JgtEX4yapOQGP1AebrLJzWsXD-QjQi1lo5JMZRooNXeBuwHXoYLHOYM2OoiXkKv_GUwzYFY2VNFxvo0xtqxRR9F-7z04X8fE-uW2GtnJQ3E_tpvYV-oL9Ti0U2hVJFjMMZslcfW-5DWj9zShojEFrBuLCLZR_9CmzLQCwy-psw8rxBgvkNhhpZd8F8NppE7Stbq_8u-GTKS8_XQ9Keqnl5BZP1AzTYP2bDV7i7_9hLEeda0iocNJeNFDzJ0R5Fn142JzA-uzsdBfLhldPxPdMhIPS0H1-M1cYtlnejwdBDfBXZjHXTFOg4BhuOtvTfrVDEmAZG2ew5ezYV-Ew2fVzVAivNTyPHzwSr29AlMAe8f6g-zuWDts-GusAmdBSkv3P7qnB4GpMEEHwsRPEPV6yTe5VDJxp8iXClLRmtnGG1VHva3oCPHQd9QJsrbFd1Kzu-2Khvz8uzZsXqX3urj4rnMBNCXNUG83zf6Yp1C2yXKdxA_KJjGOfRfb0Vh7MKDShEuV-M9_4_nq6svF4EAAA=)):
147+
As an authoring convenience, snippets declared directly _inside_ a component implicitly become props _on_ the component ([demo](/playground/untitled#H4sIAAAAAAAAE3VSTa_aMBD8Kyu_SkAbCA-JSzBR20N_QXt6vIMTO8SqsY29tI2s_PcqTiB8vaPHs7MzuxuIZgdBMvJLo0QlOElIJZXwJHsLBBvb_XUASc7Mb9Yu_B-hsMMK5sUzvDQahUZPMkJ96aTFfKd3KA_WOISfrFACKmcOMFmk8TWUTjY73RFLoz1C5U4SPWzhrcN2GKDrlcGEWauEnyRwxCaDdQLWyVJksII2uaMWTDPNLtzX5YX8-kgua-GcHJVXI3u5WEPb0d83O03TMZSmfRzOkG1Db7mNacOL19JagVALxoWbztq-H8U6j0SaYp2P2BGbOyQ2v8PQIFMXLKRDk177pq0zf6d8bMrzwBdd0pamyPMb-IjNEzS2f86Gz_Dwf-2F9nvNSUJQ_EOSoTuJNvngqK5v4Pas7n4-OCwlEEJcQTIMO-nSQwtb-GSdsX46e9gbRoP9yGQ11I0rEuycunu6PHx1QnPhxm3SFN15MOlYEFJZtf0dUywMbwZOeBGsrKNLYB54-1R9WNqVdki7usim6VmQphf7mnpshiQRhNAXdoOfMyX3OgMlKtz0cGEcF27uLSul3mewjPjgOOoDukxjPS9rqfh0pb-8zs6aBSt_7505aZ7B9xOi0T9YKW4UooVsr0zB1BTrWQJ3EL-oWcZ572GxFoezCk37QLe3897-B2i2U62uBAAA)):
148148

149149
```svelte
150150
<!-- this is semantically the same as the above -->
@@ -165,7 +165,7 @@ As an authoring convenience, snippets declared directly _inside_ a component imp
165165
</Table>
166166
```
167167

168-
Any content inside the component tags that is _not_ a snippet declaration implicitly becomes part of the `children` snippet ([demo](/playground/untitled#H4sIAAAAAAAAE41S247aMBD9lVFYCegGsiDxks1G7T_0bdkHJ3aI1cR27aEtsvzvtZ0LZeGhiiJ5js-cmTMemzS8YybJ320iSM-SPPmmVJImeFEhML9Yh8zHRp51HZDC1JorLI_iiLxXUiN8J1XHoNGyh-U2i9F2SFy-epon1lIY9IwzRwNv8B6wI1oIJXNYEqV8E8sUfuIlh0MKSvPaX-zBpZ-oFRH-m7m7l5m8uyfXLdOaX5X3V_bL9gAu0D98i0V2NSWKwQ4lSN7s0LKLbgtsyxgXmT9NiBe-iaP-DYISSTcj4bcLI7hSDEHL3yu6dkPfBdLS0m1o3nk-LW9gX-gBGss9ZsMXuLu32VjZBdfRaelft5eUN5zRJEd9Zi6dlyEy_ncdOm_IxsGlULe8o5qJNFgE5x_9SWmpzGp9N2-MXQxz4c2cOQ-lZWQyF0Jd2q_-mjI9U1fr4FBPE8iuKTbjjRt2sMBK0svIsQtG6jb2CsQAdQ_1x9f5R9tmIS-yPToK-tNkQRQGL6ObCIIdEpH9wQ3p-Enk0LEGXwe4ktoX2hhFai5Ofi0jPnYc9QF1LrDdRK-rvXjerSfNitQ_TlqeBc1hwRi7yY3F81MnK9KtsF2n8Amis44ilA7VtwfWTyr-kaKV-_X4cH8BTOhfRzcEAAA=)):
168+
Any content inside the component tags that is _not_ a snippet declaration implicitly becomes part of the `children` snippet ([demo](/playground/untitled#H4sIAAAAAAAAE3WOQQrCMBBFrzIMggql3ddY1Du4si5sOmIwnYRkFKX07lKqglqX8_7_w2uRDw1hjlsWI5ZqTPBoLEXMdy3K3fdZDzB5Ndfep_FKVnpWHSKNce1YiCVijirqYLwUJQOYxrsgsLmIOIZjcA1M02w4n-PpomSVvTclqyEutDX6DA2pZ7_ABIVugrmEC3XJH92P55_G39GodCmWBFrQJ2PrQAwdLGHig_NxNv9xrQa1dhWIawrv1Wzeqawa8953D-8QOmaEAQAA)):
169169

170170
```svelte
171171
<!--- file: App.svelte --->

documentation/docs/03-template-syntax/11-bind.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,34 @@ The general syntax is `bind:property={expression}`, where `expression` is an _lv
1212
<input bind:value />
1313
```
1414

15+
1516
Svelte creates an event listener that updates the bound value. If an element already has a listener for the same event, that listener will be fired before the bound value is updated.
1617

1718
Most bindings are _two-way_, meaning that changes to the value will affect the element and vice versa. A few bindings are _readonly_, meaning that changing their value will have no effect on the element.
1819

20+
## Function bindings
21+
22+
You can also use `bind:property={get, set}`, where `get` and `set` are functions, allowing you to perform validation and transformation:
23+
24+
```svelte
25+
<input bind:value={
26+
() => value,
27+
(v) => value = v.toLowerCase()}
28+
/>
29+
```
30+
31+
In the case of readonly bindings like [dimension bindings](#Dimensions), the `get` value should be `null`:
32+
33+
```svelte
34+
<div
35+
bind:clientWidth={null, redraw}
36+
bind:clientHeight={null, redraw}
37+
>...</div>
38+
```
39+
40+
> [!NOTE]
41+
> Function bindings are available in Svelte 5.9.0 and newer.
42+
1943
## `<input bind:value>`
2044

2145
A `bind:value` directive on an `<input>` element binds the input's `value` property:

documentation/docs/06-runtime/01-stores.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const userState = $state({
4949
```svelte
5050
<!--- file: App.svelte --->
5151
<script>
52-
import { userState } from './state.svelte';
52+
import { userState } from './state.svelte.js';
5353
</script>
5454
5555
<p>User name: {userState.name}</p>

documentation/docs/06-runtime/02-context.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const myGlobalState = $state({
2222
```svelte
2323
<!--- file: App.svelte --->
2424
<script>
25-
import { myGlobalState } from './state.svelte';
25+
import { myGlobalState } from './state.svelte.js';
2626
// ...
2727
</script>
2828
```

documentation/docs/06-runtime/04-imperative-component-api.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,22 @@ Note that unlike calling `new App(...)` in Svelte 4, things like effects (includ
3333

3434
## `unmount`
3535

36-
Unmounts a component created with [`mount`](#mount) or [`hydrate`](#hydrate):
36+
Unmounts a component that was previously created with [`mount`](#mount) or [`hydrate`](#hydrate).
37+
38+
If `options.outro` is `true`, [transitions](transition) will play before the component is removed from the DOM:
3739

3840
```js
39-
// @errors: 1109
4041
import { mount, unmount } from 'svelte';
4142
import App from './App.svelte';
4243

43-
const app = mount(App, {...});
44+
const app = mount(App, { target: document.body });
4445

4546
// later
46-
unmount(app);
47+
unmount(app, { outro: true });
4748
```
4849

50+
Returns a `Promise` that resolves after transitions have completed if `options.outro` is true, or immediately otherwise.
51+
4952
## `render`
5053

5154
Only available on the server and when compiling with the `server` option. Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app:

documentation/docs/07-misc/07-v5-migration-guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ The `foreign` namespace was only useful for Svelte Native, which we're planning
823823

824824
`afterUpdate` callbacks in a parent component will now run after `afterUpdate` callbacks in any child components.
825825

826+
`beforeUpdate/afterUpdate` no longer run when the component contains a `<slot>` and its content is updated.
827+
826828
Both functions are disallowed in runes mode — use `$effect.pre(...)` and `$effect(...)` instead.
827829

828830
### `contenteditable` behavior change

documentation/docs/98-reference/.generated/client-warnings.md

Lines changed: 75 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ The easiest way to log a value as it changes over time is to use the [`$inspect`
6666
The `%attribute%` attribute on `%html%` changed its value between server and client renders. The client value, `%value%`, will be ignored in favour of the server value
6767
```
6868

69+
Certain attributes like `src` on an `<img>` element will not be repaired during hydration, i.e. the server value will be kept. That's because updating these attributes can cause the image to be refetched (or in the case of an `<iframe>`, for the frame to be reloaded), even if they resolve to the same resource.
70+
71+
To fix this, either silence the warning with a [`svelte-ignore`](basic-markup#Comments) comment, or ensure that the value stays the same between server and client. If you really need the value to change on hydration, you can force an update like this:
72+
73+
```svelte
74+
<script>
75+
let { src } = $props();
76+
77+
if (typeof window !== 'undefined') {
78+
// stash the value...
79+
const initial = src;
80+
81+
// unset it...
82+
src = undefined;
83+
84+
$effect(() => {
85+
// ...and reset after we've mounted
86+
src = initial;
87+
});
88+
}
89+
</script>
90+
91+
<img {src} />
92+
```
93+
6994
### hydration_html_changed
7095
7196
```
@@ -76,6 +101,31 @@ The value of an `{@html ...}` block changed between server and client renders. T
76101
The value of an `{@html ...}` block %location% changed between server and client renders. The client value will be ignored in favour of the server value
77102
```
78103
104+
If the `{@html ...}` value changes between the server and the client, it will not be repaired during hydration, i.e. the server value will be kept. That's because change detection during hydration is expensive and usually unnecessary.
105+
106+
To fix this, either silence the warning with a [`svelte-ignore`](basic-markup#Comments) comment, or ensure that the value stays the same between server and client. If you really need the value to change on hydration, you can force an update like this:
107+
108+
```svelte
109+
<script>
110+
let { markup } = $props();
111+
112+
if (typeof window !== 'undefined') {
113+
// stash the value...
114+
const initial = markup;
115+
116+
// unset it...
117+
markup = undefined;
118+
119+
$effect(() => {
120+
// ...and reset after we've mounted
121+
markup = initial;
122+
});
123+
}
124+
</script>
125+
126+
{@html markup}
127+
```
128+
79129
### hydration_mismatch
80130
81131
```
@@ -86,6 +136,10 @@ Hydration failed because the initial UI does not match what was rendered on the
86136
Hydration failed because the initial UI does not match what was rendered on the server. The error occurred near %location%
87137
```
88138
139+
This warning is thrown when Svelte encounters an error while hydrating the HTML from the server. During hydration, Svelte walks the DOM, expecting a certain structure. If that structure is different (for example because the HTML was repaired by the DOM because of invalid HTML), then Svelte will run into issues, resulting in this warning.
140+
141+
During development, this error is often preceeded by a `console.error` detailing the offending HTML, which needs fixing.
142+
89143
### invalid_raw_snippet_render
90144
91145
```
@@ -110,6 +164,10 @@ Tried to unmount a component that was not mounted
110164
%parent% passed a value to %child% with `bind:`, but the value is owned by %owner%. Consider creating a binding between %owner% and %parent%
111165
```
112166

167+
Consider three components `GrandParent`, `Parent` and `Child`. If you do `<GrandParent bind:value>`, inside `GrandParent` pass on the variable via `<Parent {value} />` (note the missing `bind:`) and then do `<Child bind:value>` inside `Parent`, this warning is thrown.
168+
169+
To fix it, `bind:` to the value instead of just passing a property (i.e. in this example do `<Parent bind:value />`).
170+
113171
### ownership_invalid_mutation
114172

115173
```
@@ -120,45 +178,31 @@ Mutating a value outside the component that created it is strongly discouraged.
120178
%component% mutated a value owned by %owner%. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead
121179
```
122180

123-
### reactive_declaration_non_reactive_property
124-
125-
```
126-
A `$:` statement (%location%) read reactive state that was not visible to the compiler. Updates to this state will not cause the statement to re-run. The behaviour of this code will change if you migrate it to runes mode
127-
```
128-
129-
In legacy mode, a `$:` [reactive statement](https://svelte.dev/docs/svelte/legacy-reactive-assignments) re-runs when the state it _references_ changes. This is determined at compile time, by analysing the code.
130-
131-
In runes mode, effects and deriveds re-run when there are changes to the values that are read during the function's _execution_.
181+
Consider the following code:
132182

133-
Often, the result is the same — for example these can be considered equivalent:
134-
135-
```js
136-
let a = 1, b = 2, sum = 3;
137-
// ---cut---
138-
$: sum = a + b;
139-
```
183+
```svelte
184+
<!--- file: App.svelte --->
185+
<script>
186+
import Child from './Child.svelte';
187+
let person = $state({ name: 'Florida', surname: 'Man' });
188+
</script>
140189

141-
```js
142-
let a = 1, b = 2;
143-
// ---cut---
144-
const sum = $derived(a + b);
190+
<Child {person} />
145191
```
146192
147-
In some cases — such as the one that triggered the above warning — they are _not_ the same:
148-
149-
```js
150-
let a = 1, b = 2, sum = 3;
151-
// ---cut---
152-
const add = () => a + b;
193+
```svelte
194+
<!--- file: Child.svelte --->
195+
<script>
196+
let { person } = $props();
197+
</script>
153198

154-
// the compiler can't 'see' that `sum` depends on `a` and `b`, but
155-
// they _would_ be read while executing the `$derived` version
156-
$: sum = add();
199+
<input bind:value={person.name}>
200+
<input bind:value={person.surname}>
157201
```
158202
159-
Similarly, reactive properties of [deep state](https://svelte.dev/docs/svelte/$state#Deep-state) are not visible to the compiler. As such, changes to these properties will cause effects and deriveds to re-run but will _not_ cause `$:` statements to re-run.
203+
`Child` is mutating `person` which is owned by `App` without being explicitly "allowed" to do so. This is strongly discouraged since it can create code that is hard to reason about at scale ("who mutated this value?"), hence the warning.
160204
161-
When you [migrate this component](https://svelte.dev/docs/svelte/v5-migration-guide) to runes mode, the behaviour will change accordingly.
205+
To fix it, either create callback props to communicate changes, or mark `person` as [`$bindable`]($bindable).
162206
163207
### state_proxy_equality_mismatch
164208

documentation/docs/98-reference/.generated/compile-errors.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ Sequence expressions are not allowed as attribute/directive values in runes mode
7878
Attribute values containing `{...}` must be enclosed in quote marks, unless the value only contains the expression
7979
```
8080

81+
### bind_group_invalid_expression
82+
83+
```
84+
`bind:group` can only bind to an Identifier or MemberExpression
85+
```
86+
8187
### bind_invalid_expression
8288

8389
```
84-
Can only bind to an Identifier or MemberExpression
90+
Can only bind to an Identifier or MemberExpression or a `{get, set}` pair
8591
```
8692

8793
### bind_invalid_name
@@ -94,6 +100,12 @@ Can only bind to an Identifier or MemberExpression
94100
`bind:%name%` is not a valid binding. %explanation%
95101
```
96102

103+
### bind_invalid_parens
104+
105+
```
106+
`bind:%name%={get, set}` must not have surrounding parentheses
107+
```
108+
97109
### bind_invalid_target
98110

99111
```
@@ -430,6 +442,18 @@ Expected whitespace
430442
Imports of `svelte/internal/*` are forbidden. It contains private runtime code which is subject to change without notice. If you're importing from `svelte/internal/*` to work around a limitation of Svelte, please open an issue at https://github.com/sveltejs/svelte and explain your use case
431443
```
432444

445+
### inspect_trace_generator
446+
447+
```
448+
`$inspect.trace(...)` cannot be used inside a generator function
449+
```
450+
451+
### inspect_trace_invalid_placement
452+
453+
```
454+
`$inspect.trace(...)` must be the first statement of a function body
455+
```
456+
433457
### invalid_arguments_usage
434458

435459
```

0 commit comments

Comments
 (0)