Skip to content

Commit 954eb8d

Browse files
committed
merge main
2 parents ea75c5e + e25c281 commit 954eb8d

File tree

18 files changed

+175
-66
lines changed

18 files changed

+175
-66
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.

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 jsdocComment = /@type {.+} (?:\w+|\[.*?\]) - (.+)/.exec(comment_node.value);
1677+
if (jsdocComment) {
1678+
cleaned_comment += jsdocComment[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 & 2 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,
@@ -117,7 +117,7 @@ export {
117117
mutable_source,
118118
mutate,
119119
set,
120-
source as state,
120+
state,
121121
update,
122122
update_pre,
123123
get_options

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

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
set_reaction_sources,
1616
check_dirtiness,
1717
untracking,
18-
is_destroying_effect
18+
is_destroying_effect,
19+
push_reaction_value
1920
} from '../runtime.js';
2021
import { equals, safe_equals } from './equality.js';
2122
import {
@@ -93,14 +94,6 @@ export function source(v, o, stack) {
9394
o
9495
};
9596

96-
if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
97-
if (reaction_sources === null) {
98-
set_reaction_sources([signal]);
99-
} else {
100-
reaction_sources.push(signal);
101-
}
102-
}
103-
10497
if (DEV && tracing_mode_flag) {
10598
signal.created = stack ?? get_stack('CreatedAt');
10699
signal.debug = null;
@@ -109,8 +102,6 @@ export function source(v, o, stack) {
109102
return signal;
110103
}
111104

112-
export { source as state };
113-
114105
/**
115106
* @param {Source} source
116107
* @returns {ValueOptions | undefined}
@@ -119,6 +110,20 @@ export function get_options(source) {
119110
return source.o;
120111
}
121112

113+
/**
114+
* @template V
115+
* @param {V} v
116+
* @param {ValueOptions} [o]
117+
* @param {Error | null} [stack]
118+
*/
119+
export function state(v, o, stack) {
120+
const s = source(v, o, stack);
121+
122+
push_reaction_value(s);
123+
124+
return s;
125+
}
126+
122127
/**
123128
* @template V
124129
* @param {V} initial_value

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ export function set_reaction_sources(sources) {
101101
reaction_sources = sources;
102102
}
103103

104+
/** @param {Value} value */
105+
export function push_reaction_value(value) {
106+
if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
107+
if (reaction_sources === null) {
108+
set_reaction_sources([value]);
109+
} else {
110+
reaction_sources.push(value);
111+
}
112+
}
113+
}
114+
104115
/**
105116
* The dependencies of the reaction that is currently being executed. In many cases,
106117
* the dependencies are unchanged between runs, and so this will be `null` unless
@@ -875,21 +886,23 @@ export function get(signal) {
875886

876887
// Register the dependency on the current reaction signal.
877888
if (active_reaction !== null && !untracking) {
878-
var deps = active_reaction.deps;
879-
if (signal.rv < read_version) {
880-
signal.rv = read_version;
881-
// If the signal is accessing the same dependencies in the same
882-
// order as it did last time, increment `skipped_deps`
883-
// rather than updating `new_deps`, which creates GC cost
884-
if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
885-
skipped_deps++;
886-
} else if (new_deps === null) {
887-
new_deps = [signal];
888-
} else if (!skip_reaction || !new_deps.includes(signal)) {
889-
// Normally we can push duplicated dependencies to `new_deps`, but if we're inside
890-
// an unowned derived because skip_reaction is true, then we need to ensure that
891-
// we don't have duplicates
892-
new_deps.push(signal);
889+
if (!reaction_sources?.includes(signal)) {
890+
var deps = active_reaction.deps;
891+
if (signal.rv < read_version) {
892+
signal.rv = read_version;
893+
// If the signal is accessing the same dependencies in the same
894+
// order as it did last time, increment `skipped_deps`
895+
// rather than updating `new_deps`, which creates GC cost
896+
if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
897+
skipped_deps++;
898+
} else if (new_deps === null) {
899+
new_deps = [signal];
900+
} else if (!skip_reaction || !new_deps.includes(signal)) {
901+
// Normally we can push duplicated dependencies to `new_deps`, but if we're inside
902+
// an unowned derived because skip_reaction is true, then we need to ensure that
903+
// we don't have duplicates
904+
new_deps.push(signal);
905+
}
893906
}
894907
}
895908
} else if (

0 commit comments

Comments
 (0)