-
-
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: correctly compile $effect.root in svelte modules (#12315)
Fixes #12222
- Loading branch information
Showing
5 changed files
with
75 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: correctly compile $effect.root in svelte modules |
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
30 changes: 30 additions & 0 deletions
30
packages/svelte/tests/runtime-runes/samples/effect-root-3/_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,30 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: '<button>0</button><button>0</button><button>cleanup</button>', | ||
|
||
async test({ assert, target, logs }) { | ||
const [b1, b2, b3] = target.querySelectorAll('button'); | ||
|
||
flushSync(() => { | ||
b1.click(); | ||
b2.click(); | ||
}); | ||
|
||
assert.deepEqual(logs, [0, 1]); | ||
|
||
flushSync(() => { | ||
b3.click(); | ||
}); | ||
|
||
assert.deepEqual(logs, [0, 1, 'cleanup 1', 'cleanup 2']); | ||
|
||
flushSync(() => { | ||
b1.click(); | ||
b2.click(); | ||
}); | ||
|
||
assert.deepEqual(logs, [0, 1, 'cleanup 1', 'cleanup 2']); | ||
} | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/svelte/tests/runtime-runes/samples/effect-root-3/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,11 @@ | ||
<script> | ||
import { with_root } from './root.svelte.js'; | ||
let x = $state(0); | ||
let y = $state(0); | ||
const cleanup = with_root(() => x) | ||
</script> | ||
|
||
<button onclick={() => x++}>{x}</button> | ||
<button onclick={() => y++}>{y}</button> | ||
<button onclick={cleanup}>cleanup</button> |
20 changes: 20 additions & 0 deletions
20
packages/svelte/tests/runtime-runes/samples/effect-root-3/root.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,20 @@ | ||
export function with_root(get_x) { | ||
const cleanup = $effect.root(() => { | ||
$effect(() => { | ||
console.log(get_x()); | ||
}); | ||
|
||
const nested_cleanup = $effect.root(() => { | ||
return () => { | ||
console.log('cleanup 2'); | ||
}; | ||
}); | ||
|
||
return () => { | ||
console.log('cleanup 1'); | ||
nested_cleanup(); | ||
}; | ||
}); | ||
|
||
return cleanup; | ||
} |