-
-
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 effect_tracking correctly handles tracking reactions (#14005
) * fix: ensure effect_tracking correctly handles tracking reactions * fix: ensure effect_tracking correctly handles tracking reactions
- Loading branch information
Showing
5 changed files
with
60 additions
and
2 deletions.
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 effect_tracking correctly handles tracking reactions |
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
19 changes: 19 additions & 0 deletions
19
packages/svelte/tests/runtime-runes/samples/derived-unowned-10/_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,19 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
async test({ assert, target, logs }) { | ||
let btn1 = target.querySelector('button'); | ||
|
||
btn1?.click(); | ||
flushSync(); | ||
|
||
btn1?.click(); | ||
flushSync(); | ||
|
||
btn1?.click(); | ||
flushSync(); | ||
|
||
assert.deepEqual(logs, ['light', 'dark', 'light']); | ||
} | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/svelte/tests/runtime-runes/samples/derived-unowned-10/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,13 @@ | ||
<script> | ||
import { store, themeState } from './theme.svelte.js'; | ||
let i = 0; | ||
const increment = () => { | ||
store.update(() => ({ theme: ++i % 2 == 0 ? 'dark' : 'light' })); | ||
} | ||
</script> | ||
|
||
<button onclick={increment}>+</button> | ||
|
||
{themeState.value.theme} |
18 changes: 18 additions & 0 deletions
18
packages/svelte/tests/runtime-runes/samples/derived-unowned-10/theme.svelte.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,18 @@ | ||
import { fromStore, writable } from 'svelte/store'; | ||
|
||
export const store = writable({ theme: 'dark' }); | ||
|
||
class ThemeState { | ||
#storeState = fromStore(store); | ||
value = $derived(this.#storeState.current); | ||
|
||
constructor() { | ||
$effect.root(() => { | ||
$effect(() => { | ||
console.log(this.value.theme); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
export const themeState = new ThemeState(); |