Skip to content

Commit

Permalink
fix: more exhaustive check during SvelteMap.set in deriveds
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Oct 26, 2024
1 parent 7be3afb commit 290dfa5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-candles-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: more exhaustive check during `SvelteMap.set` in deriveds
11 changes: 5 additions & 6 deletions packages/svelte/src/reactivity/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
import { increment } from './utils.js';
import { DERIVED } from '../internal/client/constants.js';

/**
* @template K
Expand Down Expand Up @@ -102,12 +103,10 @@ 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
const needs_version_increase = !s.reactions?.every((r) => version.reactions?.includes(r));
if (needs_version_increase) {
increment(version);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { test } from '../../test';

export default test({
html: `Loading`,
compileOptions: {
// dev: true
},

async test({ assert, target }) {
await Promise.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 290dfa5

Please sign in to comment.