fix: more exhaustive check during `SvelteMap.set` in deriveds (#13951)

* fix: more exhaustive check during `SvelteMap.set` in deriveds

* chore: use set for version reactions

* chore: cleanup
pull/13967/head
Paolo Ricciuti 2 months ago committed by GitHub
parent 5ab65e3d59
commit 67cf3871b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: more exhaustive check during `SvelteMap.set` in deriveds

@ -1,6 +1,6 @@
/** @import { Source } from '#client' */
import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js';
import { set, source } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
import { increment } from './utils.js';
@ -102,12 +102,15 @@ export class SvelteMap extends Map {
increment(version);
} else if (prev_res !== value) {
increment(s);
// If no one listening to this property and is listening to the version, or
// the inverse, then we should increment the version to be safe
if (
(s.reactions === null && version.reactions !== null) ||
(s.reactions !== null && version.reactions === null)
) {
// if not every reaction of s is a reaction of version we need to also include version
var v_reactions = version.reactions === null ? null : new Set(version.reactions);
var needs_version_increase =
v_reactions === null ||
!s.reactions?.every((r) =>
/** @type {NonNullable<typeof v_reactions>} */ (v_reactions).has(r)
);
if (needs_version_increase) {
increment(version);
}
}

@ -3,7 +3,6 @@ import { test } from '../../test';
export default test({
html: `Loading`,
async test({ assert, target }) {
await Promise.resolve();
flushSync();

@ -24,6 +24,10 @@
}
const value = $derived(get_async(1));
const value2 = $derived(get_async(1));
// both values are read before the set
value;
value2;
</script>
{#if value instanceof Promise}

Loading…
Cancel
Save