Merge branch 'main' into svelte-dev-meta

pull/16255/head
Simon Holthausen 3 months ago
commit 499ed03021

@ -1,5 +1,11 @@
# svelte # svelte
## 5.34.9
### Patch Changes
- fix: ensure unowned deriveds can add themselves as reactions while connected ([#16249](https://github.com/sveltejs/svelte/pull/16249))
## 5.34.8 ## 5.34.8
### Patch Changes ### Patch Changes

@ -2,7 +2,7 @@
"name": "svelte", "name": "svelte",
"description": "Cybernetically enhanced web apps", "description": "Cybernetically enhanced web apps",
"license": "MIT", "license": "MIT",
"version": "5.34.8", "version": "5.34.9",
"type": "module", "type": "module",
"types": "./types/index.d.ts", "types": "./types/index.d.ts",
"engines": { "engines": {

@ -294,7 +294,12 @@ export function update_reaction(reaction) {
reaction.deps = deps = new_deps; reaction.deps = deps = new_deps;
} }
if (!skip_reaction) { if (
!skip_reaction ||
// Deriveds that already have reactions can cleanup, so we still add them as reactions
((flags & DERIVED) !== 0 &&
/** @type {import('#client').Derived} */ (reaction).reactions !== null)
) {
for (i = skipped_deps; i < deps.length; i++) { for (i = skipped_deps; i < deps.length; i++) {
(deps[i].reactions ??= []).push(reaction); (deps[i].reactions ??= []).push(reaction);
} }

@ -4,5 +4,5 @@
* The current version, as set in package.json. * The current version, as set in package.json.
* @type {string} * @type {string}
*/ */
export const VERSION = '5.34.8'; export const VERSION = '5.34.9';
export const PUBLIC_VERSION = '5'; export const PUBLIC_VERSION = '5';

@ -112,6 +112,45 @@ describe('signals', () => {
}; };
}); });
test('unowned deriveds are not added as reactions but trigger effects', () => {
var obj = state<any>(undefined);
class C1 {
#v = state(0);
get v() {
return $.get(this.#v);
}
set v(v: number) {
set(this.#v, v);
}
}
return () => {
let d = derived(() => $.get(obj)?.v || '-');
const log: number[] = [];
assert.equal($.get(d), '-');
let destroy = effect_root(() => {
render_effect(() => {
log.push($.get(d));
});
});
set(obj, new C1());
flushSync();
assert.equal($.get(d), '-');
$.get(obj).v = 1;
flushSync();
assert.equal($.get(d), 1);
assert.deepEqual(log, ['-', 1]);
destroy();
// ensure we're not leaking reactions
assert.equal(obj.reactions, null);
assert.equal(d.reactions, null);
};
});
test('derived from state', () => { test('derived from state', () => {
const log: number[] = []; const log: number[] = [];

Loading…
Cancel
Save