mirror of https://github.com/sveltejs/svelte
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 derivedspull/13891/head
parent
041e563466
commit
5a54ad9cc7
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ensure SvelteMap reactivity persists through deriveds
|
@ -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`);
|
||||||
|
}
|
||||||
|
});
|
@ -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}
|
||||||
|
|
Loading…
Reference in new issue