Skip to content

Commit 29406c9

Browse files
committed
merge main
2 parents 53b9b8f + 2e27c5d commit 29406c9

File tree

113 files changed

+1373
-360
lines changed

Some content is hidden

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

113 files changed

+1373
-360
lines changed

documentation/docs/02-runes/02-$state.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ Unlike other frameworks you may have encountered, there is no API for interactin
2020

2121
If `$state` is used with an array or a simple object, the result is a deeply reactive _state proxy_. [Proxies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) allow Svelte to run code when you read or write properties, including via methods like `array.push(...)`, triggering granular updates.
2222

23-
> [!NOTE] Class instances are not proxied. You can create [reactive state fields](#Classes) on classes that you define. Svelte provides reactive implementations of built-ins like `Set` and `Map` that can be imported from [`svelte/reactivity`](svelte-reactivity).
24-
25-
State is proxified recursively until Svelte finds something other than an array or simple object. In a case like this...
23+
State is proxified recursively until Svelte finds something other than an array or simple object (like a class). In a case like this...
2624

2725
```js
2826
let todos = $state([
@@ -67,7 +65,7 @@ todos[0].done = !todos[0].done;
6765

6866
### Classes
6967

70-
You can also use `$state` in class fields (whether public or private), or as the first assignment to a property immediately inside the `constructor`:
68+
Class instances are not proxied. Instead, you can use `$state` in class fields (whether public or private), or as the first assignment to a property immediately inside the `constructor`:
7169

7270
```js
7371
// @errors: 7006 2554
@@ -121,6 +119,8 @@ class Todo {
121119
}
122120
```
123121

122+
> Svelte provides reactive implementations of built-in classes like `Set` and `Map` that can be imported from [`svelte/reactivity`](svelte-reactivity).
123+
124124
## `$state.raw`
125125

126126
In cases where you don't want objects and arrays to be deeply reactive you can use `$state.raw`.
@@ -145,6 +145,8 @@ person = {
145145

146146
This can improve performance with large arrays and objects that you weren't planning to mutate anyway, since it avoids the cost of making them reactive. Note that raw state can _contain_ reactive state (for example, a raw array of reactive objects).
147147

148+
As with `$state`, you can declare class fields using `$state.raw`.
149+
148150
## `$state.snapshot`
149151

150152
To take a static snapshot of a deeply reactive `$state` proxy, use `$state.snapshot`:

documentation/docs/02-runes/04-$effect.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ In general, `$effect` is best considered something of an escape hatch — useful
269269
270270
If you're using an effect because you want to be able to reassign the derived value (to build an optimistic UI, for example) note that [deriveds can be directly overridden]($derived#Overriding-derived-values) as of Svelte 5.25.
271271

272-
You might be tempted to do something convoluted with effects to link one value to another. The following example shows two inputs for "money spent" and "money left" that are connected to each other. If you update one, the other should update accordingly. Don't use effects for this ([demo](/playground/untitled#H4sIAAAAAAAACpVRy26DMBD8FcvKgUhtoIdeHBwp31F6MGSJkBbHwksEQvx77aWQqooq9bgzOzP7mGTdIHipPiZJowOpGJAv0po2VmfnDv4OSBErjYdneHWzBJaCjcx91TWOToUtCIEE3cig0OIty44r5l1oDtjOkyFIsv3GINQ_CNYyGegd1DVUlCR7oU9iilDUcP8S8roYs9n8p2wdYNVFm4csTx872BxNCcjr5I11fdgonEkXsjP2CoUUZWMv6m6wBz2x7yxaM-iJvWeRsvSbSVeUy5i0uf8vKA78NIeJLSZWv1I8jQjLdyK4XuTSeIdmVKJGGI4LdjVOiezwDu1yG74My8PLCQaSiroe5s_5C2PHrkVGAgAA)):
272+
You might be tempted to do something convoluted with effects to link one value to another. The following example shows two inputs for "money spent" and "money left" that are connected to each other. If you update one, the other should update accordingly. Don't use effects for this ([demo](/playground/untitled#H4sIAAAAAAAAE5WRTWrDMBCFryKGLBJoY3fRjWIHeoiu6i6UZBwEY0VE49TB-O6VxrFTSih0qe_Ne_OjHpxpEDS8O7ZMeIAnqC1hAP3RA1990hKI_Fb55v06XJA4sZ0J-IjvT47RcYyBIuzP1vO2chVHHFjxiQ2pUr3k-SZRQlbBx_LIFoEN4zJfzQph_UMQr4hRXmBd456Xy5Uqt6pPKHmkfmzyPAZL2PCnbRpg8qWYu63I7lu4gswOSRYqrPNt3CgeqqzgbNwRK1A76w76YqjFspfcQTWmK3vJHlQm1puSTVSeqdOc_r9GaeCHfUSY26TXry6Br4RSK3C6yMEGT-aqVU3YbUZ2NF6rfP2KzXgbuYzY46czdgyazy0On_FlLH3F-UDXhgIO35UGlA1rAgAA)):
273273

274274
```svelte
275275
<script>
276-
let total = 100;
276+
const total = 100;
277277
let spent = $state(0);
278278
let left = $state(total);
279279
@@ -297,32 +297,26 @@ You might be tempted to do something convoluted with effects to link one value t
297297
</label>
298298
```
299299

300-
Instead, use `oninput` callbacks or — better still — [function bindings](bind#Function-bindings) where possible ([demo](/playground/untitled#H4sIAAAAAAAAE51SsW6DMBT8FcvqABINdOhCIFKXTt06lg4GHpElYyz8iECIf69tcIIipo6-u3f3fPZMJWuBpvRzkBXyTpKSy5rLq6YRbbgATdOfmeKkrMgCBt9GPpQ66RsItFjJNBzhVScRJBobmumq5wovhSxQABLskAmSk7ckOXtMKyM22ItGhhAk4Z0R0OwIN-tIQzd-90HVhvy2HsGNiQFCMltBgd7XoecV2xzXNV7XaEcth7ZfRv7kujnsTX2Qd7USb5rFjwZkJlgJwpWRcakG04cpOS9oz-QVCuoeInXW-RyEJL-sG0b7Wy6kZWM-u7CFxM5tdrIl9qg72vB74H-y7T2iXROHyVb0CLanp1yNk4D1A1jQ91hzrQSbUtIIGLcir0ylJDm9Q7urz42bX4UwIk2xH2D5Xf4A7SeMcMQCAAA=)):
300+
Instead, use `oninput` callbacks or — better still — [function bindings](bind#Function-bindings) where possible ([demo](/playground/untitled#H4sIAAAAAAAAE5VRvW7CMBB-FcvqECQK6dDFJEgsnfoGTQdDLsjSxVjxhYKivHvPBwFUsXS8774_nwftbQva6I_e78gdvNo6Xzu_j3quG4cQtfkaNJ1DIiWA8atkE8IiHgEpYVsb4Rm-O3gCT2yji7jrXKB15StiOJKiA1lUpXrL81VCEUjFwHTGXiJZgiyf3TYIjSxq6NwR6uyifr0ohMbEZnpHH2rWf7ImS8KZGtK6osl_UqelRIyVL5b3ir5AuwWUtoXzoee6fIWy0p31e6i0XMocLfZQDuI6qtaeykGcR7UU6XWznFAZU9LN_X9B2UyVayk9f3ji0-REugen6U9upDOCcAWcLlS7GNCejWoQTqsLtrfBqHzxDu3DrUTOf0xwIm2o62H85sk6_OHG2jQWI4y_3byXXGMCAAA=)):
301301

302302
```svelte
303303
<script>
304-
let total = 100;
304+
const total = 100;
305305
let spent = $state(0);
306-
let left = $state(total);
307-
308-
function updateSpent(value) {
309-
spent = value;
310-
left = total - spent;
311-
}
306+
let left = $derived(total - spent);
312307
313-
function updateLeft(value) {
314-
left = value;
308+
+++ function updateLeft(left) {
315309
spent = total - left;
316-
}
310+
}+++
317311
</script>
318312
319313
<label>
320-
<input type="range" bind:value={() => spent, updateSpent} max={total} />
314+
<input type="range" bind:value={spent} max={total} />
321315
{spent}/{total} spent
322316
</label>
323317
324318
<label>
325-
<input type="range" bind:value={() => left, updateLeft} max={total} />
319+
<input type="range" +++bind:value={() => left, updateLeft}+++ max={total} />
326320
{left}/{total} left
327321
</label>
328322
```

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: bind:
44

55
Data ordinarily flows down, from parent to child. The `bind:` directive allows data to flow the other way, from child to parent.
66

7-
The general syntax is `bind:property={expression}`, where `expression` is an _lvalue_ (i.e. a variable or an object property). When the expression is an identifier with the same name as the property, we can omit the expression — in other words these are equivalent:
7+
The general syntax is `bind:property={expression}`, where `expression` is an [_lvalue_](https://press.rebus.community/programmingfundamentals/chapter/lvalue-and-rvalue/) (i.e. a variable or an object property). When the expression is an identifier with the same name as the property, we can omit the expression — in other words these are equivalent:
88

99
<!-- prettier-ignore -->
1010
```svelte
@@ -142,26 +142,27 @@ Checkboxes can be in an [indeterminate](https://developer.mozilla.org/en-US/docs
142142

143143
## `<input bind:group>`
144144

145-
Inputs that work together can use `bind:group`.
145+
Inputs that work together can use `bind:group` ([demo](/playground/untitled#H4sIAAAAAAAAE62T32_TMBDH_5XDQkpbrct7SCMGEvCEECDxsO7BSW6L2c227EvbKOv_jp0f6jYhQKJv5_P3PvdL1wstH1Bk4hMSGdgbRzUssFaM9VJciFtF6EV23QvubNRFR_BPUVfWXvodEkdfKT3-zl8Zzag5YETuK6csF1u9ZUIGNo4VkYQNvPYsGRfJF5JKJ8s3QRJE6WoFb2Nq6K-ck13u2Sl9Vxxhlc6QUBIFnz9Brm9ifJ6esun81XoNd860FmtwslYGlLYte5AO4aHlVhJ1gIeKWq92COt1iMtJlkhFPkgh1rHZiiF6K6BUus4G5KafGznCTlIbVUMfQZUWMJh5OrL-C_qjMYSwb1DyiH7iOEuCb1ZpWTUjfHqcwC_GWDVY3ZfmME_SGttSmD9IHaYatvWHIc6xLyqad3mq6KuqcCwnWn9p8p-p71BqP2IH81zc9w2in-od7XORP7ayCpd5YCeXI_-p59mObPF9WmwGpx3nqS2Gzw8TO3zOaS5_GqUXyQUkS3h8hOSz0ZhMESHGc0c4Hm3MAn00t1wrb0l2GZRkqvt4sXwczm6Qh8vnUJzI2LV4vAkvqWgfehTZrSSPx19WiVfFfAQAAA==)):
146146

147147
```svelte
148+
<!--- file: BurritoChooser.svelte --->
148149
<script>
149150
let tortilla = $state('Plain');
150151
151-
/** @type {Array<string>} */
152+
/** @type {string[]} */
152153
let fillings = $state([]);
153154
</script>
154155
155156
<!-- grouped radio inputs are mutually exclusive -->
156-
<input type="radio" bind:group={tortilla} value="Plain" />
157-
<input type="radio" bind:group={tortilla} value="Whole wheat" />
158-
<input type="radio" bind:group={tortilla} value="Spinach" />
157+
<label><input type="radio" bind:group={tortilla} value="Plain" /> Plain</label>
158+
<label><input type="radio" bind:group={tortilla} value="Whole wheat" /> Whole wheat</label>
159+
<label><input type="radio" bind:group={tortilla} value="Spinach" /> Spinach</label>
159160
160161
<!-- grouped checkbox inputs populate an array -->
161-
<input type="checkbox" bind:group={fillings} value="Rice" />
162-
<input type="checkbox" bind:group={fillings} value="Beans" />
163-
<input type="checkbox" bind:group={fillings} value="Cheese" />
164-
<input type="checkbox" bind:group={fillings} value="Guac (extra)" />
162+
<label><input type="checkbox" bind:group={fillings} value="Rice" /> Rice</label>
163+
<label><input type="checkbox" bind:group={fillings} value="Beans" /> Beans</label>
164+
<label><input type="checkbox" bind:group={fillings} value="Cheese" /> Cheese</label>
165+
<label><input type="checkbox" bind:group={fillings} value="Guac (extra)" /> Guac (extra)</label>
165166
```
166167

167168
> [!NOTE] `bind:group` only works if the inputs are in the same Svelte component.

documentation/docs/07-misc/04-custom-elements.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ When constructing a custom element, you can tailor several aspects by defining `
114114
...
115115
```
116116

117+
> [!NOTE] While Typescript is supported in the `extend` function, it is subject to limitations: you need to set `lang="ts"` on one of the scripts AND you can only use [erasable syntax](https://www.typescriptlang.org/tsconfig/#erasableSyntaxOnly) in it. They are not processed by script preprocessors.
118+
117119
## Caveats and limitations
118120

119121
Custom elements can be a useful way to package components for consumption in a non-Svelte app, as they will work with vanilla HTML and JavaScript as well as [most frameworks](https://custom-elements-everywhere.com/). There are, however, some important differences to be aware of:

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ Consider the following code:
216216
217217
To fix it, either create callback props to communicate changes, or mark `person` as [`$bindable`]($bindable).
218218
219+
### select_multiple_invalid_value
220+
221+
```
222+
The `value` property of a `<select multiple>` element should be an array, but it received a non-array value. The selection will be kept as is.
223+
```
224+
225+
When using `<select multiple value={...}>`, Svelte will mark all selected `<option>` elements as selected by iterating over the array passed to `value`. If `value` is not an array, Svelte will emit this warning and keep the selected options as they are.
226+
227+
To silence the warning, ensure that `value`:
228+
229+
- is an array for an explicit selection
230+
- is `null` or `undefined` to keep the selection as is
231+
219232
### state_proxy_equality_mismatch
220233
221234
```

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,12 @@ In some situations a selector may target an element that is not 'visible' to the
632632
</style>
633633
```
634634

635+
### custom_element_props_identifier
636+
637+
```
638+
Using a rest element or a non-destructured declaration with `$props()` means that Svelte can't infer what properties to expose when creating a custom element. Consider destructuring all the props or explicitly specifying the `customElement.props` option.
639+
```
640+
635641
### element_implicitly_closed
636642

637643
```

packages/svelte/CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
# svelte
22

3+
## 5.33.4
4+
5+
### Patch Changes
6+
7+
- fix: narrow `defaultChecked` to boolean ([#16009](https://github.com/sveltejs/svelte/pull/16009))
8+
9+
- fix: warn when using rest or identifier in custom elements without props option ([#16003](https://github.com/sveltejs/svelte/pull/16003))
10+
11+
## 5.33.3
12+
13+
### Patch Changes
14+
15+
- fix: allow using typescript in `customElement.extend` option ([#16001](https://github.com/sveltejs/svelte/pull/16001))
16+
17+
- fix: cleanup event handlers on media elements ([#16005](https://github.com/sveltejs/svelte/pull/16005))
18+
19+
## 5.33.2
20+
21+
### Patch Changes
22+
23+
- fix: correctly parse escaped unicode characters in css selector ([#15976](https://github.com/sveltejs/svelte/pull/15976))
24+
25+
- fix: don't mark deriveds as clean if updating during teardown ([#15997](https://github.com/sveltejs/svelte/pull/15997))
26+
27+
## 5.33.1
28+
29+
### Patch Changes
30+
31+
- fix: make deriveds on the server lazy again ([#15964](https://github.com/sveltejs/svelte/pull/15964))
32+
33+
## 5.33.0
34+
35+
### Minor Changes
36+
37+
- feat: XHTML compliance ([#15538](https://github.com/sveltejs/svelte/pull/15538))
38+
39+
- feat: add `fragments: 'html' | 'tree'` option for wider CSP compliance ([#15538](https://github.com/sveltejs/svelte/pull/15538))
40+
41+
## 5.32.2
42+
43+
### Patch Changes
44+
45+
- chore: simplify `<pre>` cleaning ([#15980](https://github.com/sveltejs/svelte/pull/15980))
46+
47+
- fix: attach `__svelte_meta` correctly to elements following a CSS wrapper ([#15982](https://github.com/sveltejs/svelte/pull/15982))
48+
49+
- fix: import untrack directly from client in `svelte/attachments` ([#15974](https://github.com/sveltejs/svelte/pull/15974))
50+
51+
## 5.32.1
52+
53+
### Patch Changes
54+
55+
- Warn when an invalid `<select multiple>` value is given ([#14816](https://github.com/sveltejs/svelte/pull/14816))
56+
357
## 5.32.0
458

559
### Minor Changes

packages/svelte/elements.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,8 @@ export interface HTMLInputAttributes extends HTMLAttributes<HTMLInputElement> {
11151115
// needs both casing variants because language tools does lowercase names of non-shorthand attributes
11161116
defaultValue?: any;
11171117
defaultvalue?: any;
1118-
defaultChecked?: any;
1119-
defaultchecked?: any;
1118+
defaultChecked?: boolean | undefined | null;
1119+
defaultchecked?: boolean | undefined | null;
11201120
width?: number | string | undefined | null;
11211121
webkitdirectory?: boolean | undefined | null;
11221122

@@ -2066,7 +2066,7 @@ export interface SvelteHTMLElements {
20662066
failed?: import('svelte').Snippet<[error: unknown, reset: () => void]>;
20672067
};
20682068

2069-
[name: string]: { [name: string]: any };
2069+
[name: string & {}]: { [name: string]: any };
20702070
}
20712071

20722072
export type ClassValue = string | import('clsx').ClassArray | import('clsx').ClassDictionary;

packages/svelte/messages/client-warnings/warnings.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ Consider the following code:
180180
181181
To fix it, either create callback props to communicate changes, or mark `person` as [`$bindable`]($bindable).
182182
183+
## select_multiple_invalid_value
184+
185+
> The `value` property of a `<select multiple>` element should be an array, but it received a non-array value. The selection will be kept as is.
186+
187+
When using `<select multiple value={...}>`, Svelte will mark all selected `<option>` elements as selected by iterating over the array passed to `value`. If `value` is not an array, Svelte will emit this warning and keep the selected options as they are.
188+
189+
To silence the warning, ensure that `value`:
190+
191+
- is an array for an explicit selection
192+
- is `null` or `undefined` to keep the selection as is
193+
183194
## state_proxy_equality_mismatch
184195
185196
> Reactive `$state(...)` proxies and the values they proxy have different identities. Because of this, comparisons with `%operator%` will produce unexpected results

packages/svelte/messages/compile-warnings/script.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## custom_element_props_identifier
2+
3+
> Using a rest element or a non-destructured declaration with `$props()` means that Svelte can't infer what properties to expose when creating a custom element. Consider destructuring all the props or explicitly specifying the `customElement.props` option.
4+
15
## export_let_unused
26

37
> Component has unused export property '%name%'. If it is for external reference only, please consider using `export const %name%`

0 commit comments

Comments
 (0)