mirror of https://github.com/sveltejs/svelte
fix: address regression with untrack (#15079)
* fix: address regression with untrack * add testpull/15080/head
parent
c75f1f5f2f
commit
09510c8c5c
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: address regression with untrack
|
@ -0,0 +1,5 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `3`
|
||||
});
|
@ -0,0 +1,47 @@
|
||||
<script module>
|
||||
import { untrack } from 'svelte'
|
||||
import { SvelteMap } from 'svelte/reactivity'
|
||||
|
||||
class Foo {
|
||||
id
|
||||
updateTime = $state(Date.now())
|
||||
|
||||
constructor(id) {
|
||||
this.id = id
|
||||
}
|
||||
}
|
||||
|
||||
class Store {
|
||||
cache = new SvelteMap()
|
||||
ids = $state([1, 2, 3])
|
||||
|
||||
getOrDefault(id) {
|
||||
let ret = this.cache.get(id)
|
||||
|
||||
if (ret) {
|
||||
return ret
|
||||
}
|
||||
|
||||
ret = untrack(() => {
|
||||
ret = new Foo(id)
|
||||
this.cache.set(id, ret)
|
||||
return ret
|
||||
})
|
||||
this.cache.get(id)
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
get values() {
|
||||
return this.ids.map(id => this.getOrDefault(id)).sort((a, b) => b.updateTime - a.updateTime)
|
||||
}
|
||||
}
|
||||
|
||||
const store = new Store()
|
||||
</script>
|
||||
|
||||
<script>
|
||||
const test = $derived.by(() => store.values.length)
|
||||
</script>
|
||||
|
||||
{test}
|
Loading…
Reference in new issue