fix: make `set.has(...)` granular for existing properties (#10793)

* fix: make set.has(...) granular

* changeset

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/10792/head
Rich Harris 7 months ago committed by GitHub
parent fbbd89a917
commit 1e653ef4d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: make `set.has(...)` granular for existing properties'

@ -82,11 +82,12 @@ export class ReactiveSet extends Set {
/** @param {T} value */
has(value) {
var source = this.#sources.get(value);
// We should always track the version in case
// the Set ever gets this value in the future.
get(this.#version);
if (source === undefined) {
// We should always track the version in case
// the Set ever gets this value in the future.
get(this.#version);
return false;
}

@ -30,7 +30,50 @@ test('set.values()', () => {
set.clear();
});
assert.deepEqual(log, [5, true, [1, 2, 3, 4, 5], 4, false, [1, 2, 4, 5], 0, false, []]);
assert.deepEqual(log, [5, true, [1, 2, 3, 4, 5], 4, false, [1, 2, 4, 5], 0, [], false]); // TODO update when we fix effect ordering bug
cleanup();
});
test('set.has(...)', () => {
const set = new ReactiveSet([1, 2, 3]);
const log: any = [];
const cleanup = user_root_effect(() => {
pre_effect(() => {
log.push('has 1', set.has(1));
});
pre_effect(() => {
log.push('has 2', set.has(2));
});
pre_effect(() => {
log.push('has 3', set.has(3));
});
});
flushSync(() => {
set.delete(2);
});
flushSync(() => {
set.add(2);
});
assert.deepEqual(log, [
'has 1',
true,
'has 2',
true,
'has 3',
true,
'has 2',
false,
'has 2',
true
]);
cleanup();
});

Loading…
Cancel
Save