-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure SvelteMap reactivity persists through deriveds (#13877)
* fix: ensure SvelteMap reactivity persists through deriveds * fix: ensure SvelteMap reactivity persists through deriveds * fix: ensure SvelteMap reactivity persists through deriveds
- Loading branch information
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: ensure SvelteMap reactivity persists through deriveds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/svelte/tests/runtime-runes/samples/derived-map/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: `Loading`, | ||
|
||
async test({ assert, target }) { | ||
await Promise.resolve(); | ||
flushSync(); | ||
|
||
assert.htmlEqual(target.innerHTML, `1`); | ||
} | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/svelte/tests/runtime-runes/samples/derived-map/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script> | ||
import { untrack } from 'svelte'; | ||
import { SvelteMap } from 'svelte/reactivity'; | ||
const cache = new SvelteMap(); | ||
function get_async(id) { | ||
const model = cache.get(id); | ||
if (!model) { | ||
const promise = new Promise(async () => { | ||
await Promise.resolve(); | ||
cache.set(id, id.toString()); | ||
}).then(() => cache.get(id)); | ||
untrack(() => { | ||
cache.set(id, promise); | ||
}); | ||
return promise; | ||
} | ||
return model; | ||
} | ||
const value = $derived(get_async(1)); | ||
</script> | ||
|
||
{#if value instanceof Promise} | ||
Loading | ||
{:else} | ||
{value} | ||
{/if} | ||
|