Skip to content

Commit f5196d8

Browse files
sync svelte docs
1 parent 0485be4 commit f5196d8

File tree

9 files changed

+153
-14
lines changed

9 files changed

+153
-14
lines changed

apps/svelte.dev/content/docs/svelte/02-runes/02-$state.md

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

2222
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.
2323

24-
> [!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).
25-
26-
State is proxified recursively until Svelte finds something other than an array or simple object. In a case like this...
24+
State is proxified recursively until Svelte finds something other than an array or simple object (like a class). In a case like this...
2725

2826
```js
2927
let todos = $state([
@@ -68,7 +66,7 @@ todos[0].done = !todos[0].done;
6866

6967
### Classes
7068

71-
You can also use `$state` in class fields (whether public or private), or as the first assignment to a property immediately inside the `constructor`:
69+
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`:
7270

7371
```js
7472
// @errors: 7006 2554
@@ -122,6 +120,8 @@ class Todo {
122120
}
123121
```
124122

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

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

147147
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).
148148

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

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

apps/svelte.dev/content/docs/svelte/03-template-syntax/09-@attach.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ function foo(+++getBar+++) {
161161
## Creating attachments programmatically
162162

163163
To add attachments to an object that will be spread onto a component or element, use [`createAttachmentKey`](svelte-attachments#createAttachmentKey).
164+
165+
## Converting actions to attachments
166+
167+
If you're using a library that only provides actions, you can convert them to attachments with [`fromAction`](svelte-attachments#fromAction), allowing you to (for example) use them with components.

apps/svelte.dev/content/docs/svelte/03-template-syntax/12-bind.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,27 @@ Checkboxes can be in an [indeterminate](https://developer.mozilla.org/en-US/docs
143143

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

146-
Inputs that work together can use `bind:group`.
146+
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==)):
147147

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

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

apps/svelte.dev/content/docs/svelte/98-reference/.generated/client-warnings.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ Consider the following code:
200200
201201
To fix it, either create callback props to communicate changes, or mark `person` as [`$bindable`]($bindable).
202202
203+
### select_multiple_invalid_value
204+
205+
```
206+
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.
207+
```
208+
209+
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.
210+
211+
To silence the warning, ensure that `value`:
212+
213+
- is an array for an explicit selection
214+
- is `null` or `undefined` to keep the selection as is
215+
203216
### state_proxy_equality_mismatch
204217
205218
```

apps/svelte.dev/content/docs/svelte/98-reference/.generated/compile-warnings.md

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

635+
### element_implicitly_closed
636+
637+
```
638+
This element is implicitly closed by the following `%tag%`, which can cause an unexpected DOM structure. Add an explicit `%closing%` to avoid surprises.
639+
```
640+
641+
In HTML, some elements are implicitly closed by another element. For example, you cannot nest a `<p>` inside another `<p>`:
642+
643+
```html
644+
<!-- this HTML... -->
645+
<p><p>hello</p>
646+
647+
<!-- results in this DOM structure -->
648+
<p></p>
649+
<p>hello</p>
650+
```
651+
652+
Similarly, a parent element's closing tag will implicitly close all child elements, even if the `</` was a typo and you meant to create a _new_ element. To avoid ambiguity, it's always a good idea to have an explicit closing tag.
653+
635654
### element_invalid_self_closing_tag
636655

637656
```

apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-attachments.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: svelte/attachments
77

88
```js
99
// @noErrors
10-
import { createAttachmentKey } from 'svelte/attachments';
10+
import { createAttachmentKey, fromAction } from 'svelte/attachments';
1111
```
1212

1313
## createAttachmentKey
@@ -48,6 +48,52 @@ function createAttachmentKey(): symbol;
4848

4949

5050

51+
## fromAction
52+
53+
Converts an [action](/docs/svelte/use) into an [attachment](/docs/svelte/@attach) keeping the same behavior.
54+
It's useful if you want to start using attachments on components but you have actions provided by a library.
55+
56+
Note that the second argument, if provided, must be a function that _returns_ the argument to the
57+
action function, not the argument itself.
58+
59+
```svelte
60+
<!-- with an action -->
61+
<div use:foo={bar}>...</div>
62+
63+
<!-- with an attachment -->
64+
<div {@attach fromAction(foo, () => bar)}>...</div>
65+
```
66+
67+
<div class="ts-block">
68+
69+
```dts
70+
function fromAction<
71+
E extends EventTarget,
72+
T extends unknown
73+
>(
74+
action:
75+
| Action<E, T>
76+
| ((element: E, arg: T) => void | ActionReturn<T>),
77+
fn: () => T
78+
): Attachment<E>;
79+
```
80+
81+
</div>
82+
83+
<div class="ts-block">
84+
85+
```dts
86+
function fromAction<E extends EventTarget>(
87+
action:
88+
| Action<E, void>
89+
| ((element: E) => void | ActionReturn<void>)
90+
): Attachment<E>;
91+
```
92+
93+
</div>
94+
95+
96+
5197
## Attachment
5298

5399
An [attachment](/docs/svelte/@attach) is a function that runs when an element is mounted

apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-compiler.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,28 @@ If `true`, whitespace inside and between elements is kept as you typed it, rathe
811811

812812
<div class="ts-block-property">
813813

814+
```dts
815+
fragments?: 'html' | 'tree';
816+
```
817+
818+
<div class="ts-block-property-details">
819+
820+
<div class="ts-block-property-bullets">
821+
822+
- <span class="tag">default</span> `'html'`
823+
824+
</div>
825+
826+
Which strategy to use when cloning DOM fragments:
827+
828+
- `html` populates a `<template>` with `innerHTML` and clones it. This is faster, but cannot be used if your app's [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) includes [`require-trusted-types-for 'script'`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/require-trusted-types-for)
829+
- `tree` creates the fragment one element at a time and _then_ clones it. This is slower, but works everywhere
830+
831+
</div>
832+
</div>
833+
834+
<div class="ts-block-property">
835+
814836
```dts
815837
runes?: boolean | undefined;
816838
```

apps/svelte.dev/content/docs/svelte/98-reference/30-compiler-warnings.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,25 @@ In some situations a selector may target an element that is not 'visible' to the
653653
</style>
654654
```
655655

656+
### element_implicitly_closed
657+
658+
```
659+
This element is implicitly closed by the following `%tag%`, which can cause an unexpected DOM structure. Add an explicit `%closing%` to avoid surprises.
660+
```
661+
662+
In HTML, some elements are implicitly closed by another element. For example, you cannot nest a `<p>` inside another `<p>`:
663+
664+
```html
665+
<!-- this HTML... -->
666+
<p><p>hello</p>
667+
668+
<!-- results in this DOM structure -->
669+
<p></p>
670+
<p>hello</p>
671+
```
672+
673+
Similarly, a parent element's closing tag will implicitly close all child elements, even if the `</` was a typo and you meant to create a _new_ element. To avoid ambiguity, it's always a good idea to have an explicit closing tag.
674+
656675
### element_invalid_self_closing_tag
657676

658677
```

apps/svelte.dev/content/docs/svelte/98-reference/30-runtime-warnings.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ Consider the following code:
207207
208208
To fix it, either create callback props to communicate changes, or mark `person` as [`$bindable`]($bindable).
209209
210+
### select_multiple_invalid_value
211+
212+
```
213+
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.
214+
```
215+
216+
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.
217+
218+
To silence the warning, ensure that `value`:
219+
220+
- is an array for an explicit selection
221+
- is `null` or `undefined` to keep the selection as is
222+
210223
### state_proxy_equality_mismatch
211224
212225
```

0 commit comments

Comments
 (0)