Skip to content

Commit a4540f8

Browse files
committed
merge main
2 parents df027d0 + 85f83ec commit a4540f8

File tree

52 files changed

+900
-840
lines changed

Some content is hidden

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

52 files changed

+900
-840
lines changed

.changeset/hip-singers-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': minor
3+
---
4+
5+
feat: SSR-safe ID generation with `$props.id()`

.changeset/long-moles-join.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

documentation/docs/02-runes/05-$props.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,24 @@ You can, of course, separate the type declaration from the annotation:
199199
> [!NOTE] Interfaces for native DOM elements are provided in the `svelte/elements` module (see [Typing wrapper components](typescript#Typing-wrapper-components))
200200
201201
Adding types is recommended, as it ensures that people using your component can easily discover which props they should provide.
202+
203+
204+
## `$props.id()`
205+
206+
This rune, added in version 5.20.0, generates an ID that is unique to the current component instance. When hydrating a server-rendered component, the value will be consistent between server and client.
207+
208+
This is useful for linking elements via attributes like `for` and `aria-labelledby`.
209+
210+
```svelte
211+
<script>
212+
const uid = $props.id();
213+
</script>
214+
215+
<form>
216+
<label for="{uid}-firstname">First Name: </label>
217+
<input id="{uid}-firstname" type="text" />
218+
219+
<label for="{uid}-lastname">Last Name: </label>
220+
<input id="{uid}-lastname" type="text" />
221+
</form>
222+
```

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,13 @@ Unrecognised compiler option %keypath%
585585
### props_duplicate
586586

587587
```
588-
Cannot use `$props()` more than once
588+
Cannot use `%rune%()` more than once
589+
```
590+
591+
### props_id_invalid_placement
592+
593+
```
594+
`$props.id()` can only be used at the top level of components as a variable declaration initializer
589595
```
590596

591597
### props_illegal_name

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": "MIT",
88
"packageManager": "[email protected]",
99
"engines": {
10-
"pnpm": "^9.0.0"
10+
"pnpm": ">=9.0.0"
1111
},
1212
"repository": {
1313
"type": "git",
@@ -44,6 +44,6 @@
4444
"typescript": "^5.5.4",
4545
"typescript-eslint": "^8.2.0",
4646
"v8-natives": "^1.2.5",
47-
"vitest": "^2.0.5"
47+
"vitest": "^2.1.9"
4848
}
4949
}

packages/svelte/CHANGELOG.md

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

3+
## 5.19.10
4+
5+
### Patch Changes
6+
7+
- fix: when re-connecting unowned deriveds, remove their unowned flag ([#15255](https://github.com/sveltejs/svelte/pull/15255))
8+
9+
- fix: allow mutation of private derived state ([#15228](https://github.com/sveltejs/svelte/pull/15228))
10+
11+
## 5.19.9
12+
13+
### Patch Changes
14+
15+
- fix: ensure unowned derived dependencies are not duplicated when reactions are skipped ([#15232](https://github.com/sveltejs/svelte/pull/15232))
16+
17+
- fix: hydrate `href` that is part of spread attributes ([#15226](https://github.com/sveltejs/svelte/pull/15226))
18+
19+
## 5.19.8
20+
21+
### Patch Changes
22+
23+
- fix: properly set `value` property of custom elements ([#15206](https://github.com/sveltejs/svelte/pull/15206))
24+
25+
- fix: ensure custom element updates don't run in hydration mode ([#15217](https://github.com/sveltejs/svelte/pull/15217))
26+
27+
- fix: ensure tracking returns true, even if in unowned ([#15214](https://github.com/sveltejs/svelte/pull/15214))
28+
329
## 5.19.7
430

531
### Patch Changes

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ This turned out to be buggy and unpredictable, particularly when working with de
128128
129129
## props_duplicate
130130

131-
> Cannot use `$props()` more than once
131+
> Cannot use `%rune%()` more than once
132+
133+
## props_id_invalid_placement
134+
135+
> `$props.id()` can only be used at the top level of components as a variable declaration initializer
132136
133137
## props_illegal_name
134138

packages/svelte/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.19.7",
5+
"version": "5.19.10",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {
@@ -143,7 +143,7 @@
143143
"source-map": "^0.7.4",
144144
"tiny-glob": "^0.2.9",
145145
"typescript": "^5.5.4",
146-
"vitest": "^2.0.5"
146+
"vitest": "^2.1.9"
147147
},
148148
"dependencies": {
149149
"@ampproject/remapping": "^2.3.0",

packages/svelte/src/ambient.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ declare namespace $effect {
339339
declare function $props(): any;
340340

341341
declare namespace $props {
342+
/**
343+
* Generates an ID that is unique to the current component instance. When hydrating a server-rendered component,
344+
* the value will be consistent between server and client.
345+
*
346+
* This is useful for linking elements via attributes like `for` and `aria-labelledby`.
347+
* @since 5.20.0
348+
*/
349+
export function id(): string;
350+
342351
// prevent intellisense from being unhelpful
343352
/** @deprecated */
344353
export const apply: never;

packages/svelte/src/compiler/errors.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,22 @@ export function module_illegal_default_export(node) {
297297
}
298298

299299
/**
300-
* Cannot use `$props()` more than once
300+
* Cannot use `%rune%()` more than once
301+
* @param {null | number | NodeLike} node
302+
* @param {string} rune
303+
* @returns {never}
304+
*/
305+
export function props_duplicate(node, rune) {
306+
e(node, 'props_duplicate', `Cannot use \`${rune}()\` more than once\nhttps://svelte.dev/e/props_duplicate`);
307+
}
308+
309+
/**
310+
* `$props.id()` can only be used at the top level of components as a variable declaration initializer
301311
* @param {null | number | NodeLike} node
302312
* @returns {never}
303313
*/
304-
export function props_duplicate(node) {
305-
e(node, 'props_duplicate', `Cannot use \`$props()\` more than once\nhttps://svelte.dev/e/props_duplicate`);
314+
export function props_id_invalid_placement(node) {
315+
e(node, 'props_id_invalid_placement', `\`$props.id()\` can only be used at the top level of components as a variable declaration initializer\nhttps://svelte.dev/e/props_id_invalid_placement`);
306316
}
307317

308318
/**

0 commit comments

Comments
 (0)