Skip to content

Commit 4b8b038

Browse files
committed
Merge branch 'main' into deriveds-in-constructor
2 parents 7ac1696 + 83d0c58 commit 4b8b038

File tree

20 files changed

+177
-72
lines changed

20 files changed

+177
-72
lines changed

.changeset/dirty-pianos-sparkle.md

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

.changeset/nine-laws-rush.md

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Teardown functions also run when the effect is destroyed, which happens when its
7474

7575
`$effect` automatically picks up any reactive values (`$state`, `$derived`, `$props`) that are _synchronously_ read inside its function body (including indirectly, via function calls) and registers them as dependencies. When those dependencies change, the `$effect` schedules a re-run.
7676

77+
If `$state` and `$derived` are used directly inside the `$effect` (for example, during creation of a [reactive class](https://svelte.dev/docs/svelte/$state#Classes)), those values will _not_ be treated as dependencies.
78+
7779
Values that are read _asynchronously_ — after an `await` or inside a `setTimeout`, for example — will not be tracked. Here, the canvas will be repainted when `color` changes, but not when `size` changes ([demo](/playground/untitled#H4sIAAAAAAAAE31T246bMBD9lZF3pWSlBEirfaEQqdo_2PatVIpjBrDkGGQPJGnEv1e2IZfVal-wfHzmzJyZ4cIqqdCy9M-F0blDlnqArZjmB3f72XWRHVCRw_bc4me4aDWhJstSlllhZEfbQhekkMDKfwg5PFvihMvX5OXH_CJa1Zrb0-Kpqr5jkiwC48rieuDWQbqgZ6wqFLRcvkC-hYvnkWi1dWqa8ESQTxFRjfQWsOXiWzmr0sSLhEJu3p1YsoJkNUcdZUnN9dagrBu6FVRQHAM10sJRKgUG16bXcGxQ44AGdt7SDkTDdY02iqLHnJVU6hedlWuIp94JW6Tf8oBt_8GdTxlF0b4n0C35ZLBzXb3mmYn3ae6cOW74zj0YVzDNYXRHFt9mprNgHfZSl6mzml8CMoLvTV6wTZIUDEJv5us2iwMtiJRyAKG4tXnhl8O0yhbML0Wm-B7VNlSSSd31BG7z8oIZZ6dgIffAVY_5xdU9Qrz1Bnx8fCfwtZ7v8Qc9j3nB8PqgmMWlHIID6-bkVaPZwDySfWtKNGtquxQ23Qlsq2QJT0KIqb8dL0up6xQ2eIBkAg_c1FI_YqW0neLnFCqFpwmreedJYT7XX8FVOBfwWRhXstZrSXiwKQjUhOZeMIleb5JZfHWn2Yq5pWEpmR7Hv-N_wEqT8hEEAAA=)):
7880

7981
```ts

packages/svelte/CHANGELOG.md

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

3+
## 5.24.0
4+
5+
### Minor Changes
6+
7+
- feat: allow state created in deriveds/effects to be written/read locally without self-invalidation ([#15553](https://github.com/sveltejs/svelte/pull/15553))
8+
9+
### Patch Changes
10+
11+
- fix: check if DOM prototypes are extensible ([#15569](https://github.com/sveltejs/svelte/pull/15569))
12+
13+
- Keep inlined trailing JSDoc comments of properties when running svelte-migrate ([#15567](https://github.com/sveltejs/svelte/pull/15567))
14+
15+
- fix: simplify set calls for proxyable values ([#15548](https://github.com/sveltejs/svelte/pull/15548))
16+
17+
- fix: don't depend on deriveds created inside the current reaction ([#15564](https://github.com/sveltejs/svelte/pull/15564))
18+
319
## 5.23.2
420

521
### Patch Changes

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.23.2",
5+
"version": "5.24.0",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/src/compiler/migrate/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,6 @@ function extract_type_and_comment(declarator, state, path) {
15921592
const comment_start = /** @type {any} */ (comment_node)?.start;
15931593
const comment_end = /** @type {any} */ (comment_node)?.end;
15941594
let comment = comment_node && str.original.substring(comment_start, comment_end);
1595-
15961595
if (comment_node) {
15971596
str.update(comment_start, comment_end, '');
15981597
}
@@ -1673,6 +1672,11 @@ function extract_type_and_comment(declarator, state, path) {
16731672
state.has_type_or_fallback = true;
16741673
const match = /@type {(.+)}/.exec(comment_node.value);
16751674
if (match) {
1675+
// try to find JSDoc comments after a hyphen `-`
1676+
const jsdoc_comment = /@type {.+} (?:\w+|\[.*?\]) - (.+)/.exec(comment_node.value);
1677+
if (jsdoc_comment) {
1678+
cleaned_comment += jsdoc_comment[1]?.trim();
1679+
}
16761680
return {
16771681
type: match[1],
16781682
comment: cleaned_comment,
@@ -1693,7 +1697,6 @@ function extract_type_and_comment(declarator, state, path) {
16931697
};
16941698
}
16951699
}
1696-
16971700
return {
16981701
type: 'any',
16991702
comment: state.uses_ts ? comment : cleaned_comment,

packages/svelte/src/internal/client/dom/operations.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
33
import { DEV } from 'esm-env';
44
import { init_array_prototype_warnings } from '../dev/equality.js';
5-
import { get_descriptor } from '../../shared/utils.js';
5+
import { get_descriptor, is_extensible } from '../../shared/utils.js';
66

77
// export these for reference in the compiled code, making global name deduplication unnecessary
88
/** @type {Window} */
@@ -34,26 +34,31 @@ export function init_operations() {
3434

3535
var element_prototype = Element.prototype;
3636
var node_prototype = Node.prototype;
37+
var text_prototype = Text.prototype;
3738

3839
// @ts-ignore
3940
first_child_getter = get_descriptor(node_prototype, 'firstChild').get;
4041
// @ts-ignore
4142
next_sibling_getter = get_descriptor(node_prototype, 'nextSibling').get;
4243

43-
// the following assignments improve perf of lookups on DOM nodes
44-
// @ts-expect-error
45-
element_prototype.__click = undefined;
46-
// @ts-expect-error
47-
element_prototype.__className = undefined;
48-
// @ts-expect-error
49-
element_prototype.__attributes = null;
50-
// @ts-expect-error
51-
element_prototype.__style = undefined;
52-
// @ts-expect-error
53-
element_prototype.__e = undefined;
54-
55-
// @ts-expect-error
56-
Text.prototype.__t = undefined;
44+
if (is_extensible(element_prototype)) {
45+
// the following assignments improve perf of lookups on DOM nodes
46+
// @ts-expect-error
47+
element_prototype.__click = undefined;
48+
// @ts-expect-error
49+
element_prototype.__className = undefined;
50+
// @ts-expect-error
51+
element_prototype.__attributes = null;
52+
// @ts-expect-error
53+
element_prototype.__style = undefined;
54+
// @ts-expect-error
55+
element_prototype.__e = undefined;
56+
}
57+
58+
if (is_extensible(text_prototype)) {
59+
// @ts-expect-error
60+
text_prototype.__t = undefined;
61+
}
5762

5863
if (DEV) {
5964
// @ts-expect-error

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export {
101101
text,
102102
props_id
103103
} from './dom/template.js';
104-
export { derived, derived_safe_equal } from './reactivity/deriveds.js';
104+
export { user_derived as derived, derived_safe_equal } from './reactivity/deriveds.js';
105105
export {
106106
effect_tracking,
107107
effect_root,
@@ -113,14 +113,7 @@ export {
113113
user_effect,
114114
user_pre_effect
115115
} from './reactivity/effects.js';
116-
export {
117-
mutable_source,
118-
mutate,
119-
set,
120-
source as state,
121-
update,
122-
update_pre
123-
} from './reactivity/sources.js';
116+
export { mutable_source, mutate, set, state, update, update_pre } from './reactivity/sources.js';
124117
export {
125118
prop,
126119
rest_props,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
object_prototype
1111
} from '../shared/utils.js';
1212
import { check_ownership, widen_ownership } from './dev/ownership.js';
13-
import { source, set } from './reactivity/sources.js';
13+
import { state as source, set } from './reactivity/sources.js';
1414
import { STATE_SYMBOL, STATE_SYMBOL_METADATA } from './constants.js';
1515
import { UNINITIALIZED } from '../../constants.js';
1616
import * as e from './errors.js';

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
skip_reaction,
99
update_reaction,
1010
increment_write_version,
11-
set_active_effect
11+
set_active_effect,
12+
push_reaction_value
1213
} from '../runtime.js';
1314
import { equals, safe_equals } from './equality.js';
1415
import * as e from '../errors.js';
@@ -61,6 +62,19 @@ export function derived(fn) {
6162
return signal;
6263
}
6364

65+
/**
66+
* @template V
67+
* @param {() => V} fn
68+
* @returns {Derived<V>}
69+
*/
70+
export function user_derived(fn) {
71+
const d = derived(fn);
72+
73+
push_reaction_value(d);
74+
75+
return d;
76+
}
77+
6478
/**
6579
* @template V
6680
* @param {() => V} fn

0 commit comments

Comments
 (0)