Skip to content

Commit 422e658

Browse files
committed
Merge branch 'main' into aa
2 parents cfba900 + b2c8224 commit 422e658

File tree

12 files changed

+82
-18
lines changed

12 files changed

+82
-18
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ We use [GitHub issues](https://github.com/sveltejs/svelte/issues) for our public
5151

5252
If you have questions about using Svelte, contact us on Discord at [svelte.dev/chat](https://svelte.dev/chat), and we will do our best to answer your questions.
5353

54-
If you see anything you'd like to be implemented, create a [feature request issue](https://github.com/sveltejs/svelte/issues/new?template=feature_request.yml)
54+
If you see anything you'd like to be implemented, create a [feature request issue](https://github.com/sveltejs/svelte/issues/new?template=feature_request.yml).
5555

5656
### Reporting new issues
5757

packages/svelte/CHANGELOG.md

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

3+
## 5.19.4
4+
5+
### Patch Changes
6+
7+
- fix: Add `bind:focused` property to `HTMLAttributes` type ([#15122](https://github.com/sveltejs/svelte/pull/15122))
8+
9+
- fix: lazily connect derievds (in deriveds) to their parent ([#15129](https://github.com/sveltejs/svelte/pull/15129))
10+
11+
- fix: disallow $state/$derived in const tags ([#15115](https://github.com/sveltejs/svelte/pull/15115))
12+
313
## 5.19.3
414

515
### Patch Changes

packages/svelte/elements.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ export interface HTMLAttributes<T extends EventTarget> extends AriaAttributes, D
839839
readonly 'bind:contentBoxSize'?: Array<ResizeObserverSize> | undefined | null;
840840
readonly 'bind:borderBoxSize'?: Array<ResizeObserverSize> | undefined | null;
841841
readonly 'bind:devicePixelContentBoxSize'?: Array<ResizeObserverSize> | undefined | null;
842+
readonly 'bind:focused'?: boolean | undefined | null;
842843

843844
// SvelteKit
844845
'data-sveltekit-keepfocus'?: true | '' | 'off' | undefined | null;

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
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.3",
5+
"version": "5.19.4",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/src/compiler/phases/2-analyze/visitors/CallExpression.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export function CallExpression(node, context) {
8080
case '$derived':
8181
case '$derived.by':
8282
if (
83-
parent.type !== 'VariableDeclarator' &&
83+
(parent.type !== 'VariableDeclarator' ||
84+
get_parent(context.path, -3).type === 'ConstTag') &&
8485
!(parent.type === 'PropertyDefinition' && !parent.static && !parent.computed)
8586
) {
8687
e.state_invalid_placement(node, rune);

packages/svelte/src/internal/client/reactivity/deriveds.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ export function derived(fn) {
7272
signal.created = get_stack('CreatedAt');
7373
}
7474

75-
if (parent_derived !== null) {
76-
(parent_derived.children ??= []).push(signal);
77-
}
78-
7975
return signal;
8076
}
8177

packages/svelte/src/internal/client/runtime.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,26 +1018,30 @@ export function get(signal) {
10181018
signal.reactions.push(active_reaction);
10191019
}
10201020
}
1021-
} else if (is_derived && /** @type {Derived} */ (signal).deps === null) {
1021+
}
1022+
1023+
if (
1024+
is_derived &&
1025+
/** @type {Derived} */ (signal).deps === null &&
1026+
(active_reaction === null || untracking || (active_reaction.f & DERIVED) !== 0)
1027+
) {
10221028
var derived = /** @type {Derived} */ (signal);
10231029
var parent = derived.parent;
1024-
var target = derived;
10251030

1026-
while (parent !== null) {
1027-
// Attach the derived to the nearest parent effect, if there are deriveds
1028-
// in between then we also need to attach them too
1031+
if (parent !== null) {
1032+
// Attach the derived to the nearest parent effect or derived
10291033
if ((parent.f & DERIVED) !== 0) {
10301034
var parent_derived = /** @type {Derived} */ (parent);
10311035

1032-
target = parent_derived;
1033-
parent = parent_derived.parent;
1036+
if (!parent_derived.children?.includes(derived)) {
1037+
(parent_derived.children ??= []).push(derived);
1038+
}
10341039
} else {
10351040
var parent_effect = /** @type {Effect} */ (parent);
10361041

1037-
if (!parent_effect.deriveds?.includes(target)) {
1038-
(parent_effect.deriveds ??= []).push(target);
1042+
if (!parent_effect.deriveds?.includes(derived)) {
1043+
(parent_effect.deriveds ??= []).push(derived);
10391044
}
1040-
break;
10411045
}
10421046
}
10431047
}

packages/svelte/src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* The current version, as set in package.json.
55
* @type {string}
66
*/
7-
export const VERSION = '5.19.3';
7+
export const VERSION = '5.19.4';
88
export const PUBLIC_VERSION = '5';

packages/svelte/tests/signals/test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,33 @@ describe('signals', () => {
803803
};
804804
});
805805

806+
test('nested deriveds do not connect inside parent deriveds if unused', () => {
807+
return () => {
808+
let a = render_effect(() => {});
809+
let b: Derived<void> | undefined;
810+
811+
const destroy = effect_root(() => {
812+
a = render_effect(() => {
813+
$.untrack(() => {
814+
b = derived(() => {
815+
derived(() => {});
816+
derived(() => {});
817+
derived(() => {});
818+
});
819+
$.get(b);
820+
});
821+
});
822+
});
823+
824+
assert.deepEqual(a.deriveds?.length, 1);
825+
assert.deepEqual(b?.children, null);
826+
827+
destroy();
828+
829+
assert.deepEqual(a.deriveds, null);
830+
};
831+
});
832+
806833
test('deriveds containing effects work correctly when used with untrack', () => {
807834
return () => {
808835
let a = render_effect(() => {});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script lang="ts">
2+
let focused = $state(false);
3+
</script>
4+
5+
<input bind:focused={focused} type="text" />
6+
<textarea bind:focused={focused}></textarea>
7+
<select bind:focused={focused}></select>
8+
<div bind:focused={focused}></div>

0 commit comments

Comments
 (0)