-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: address regression with untrack (#15079)
* fix: address regression with untrack * add test
- Loading branch information
Showing
4 changed files
with
58 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: address regression with untrack |
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
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/runtime-runes/samples/untracked-derived-local/_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,5 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: `3` | ||
}); |
47 changes: 47 additions & 0 deletions
47
packages/svelte/tests/runtime-runes/samples/untracked-derived-local/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,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} |