-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure child effects are destroyed before their deriveds (#14043)
* fix: ensure legacy props cache last value when destroyed * fix runes * better approach * better approach * kill code * lint
- Loading branch information
Showing
10 changed files
with
86 additions
and
11 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 child effects are destroyed before their deriveds |
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
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
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
11 changes: 11 additions & 0 deletions
11
packages/svelte/tests/runtime-legacy/samples/props-reactive-destroy/Child.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 { onDestroy } from 'svelte'; | ||
export let data; | ||
onDestroy(() => { | ||
data; | ||
}); | ||
</script> | ||
|
||
{data ? '' : null} |
10 changes: 10 additions & 0 deletions
10
packages/svelte/tests/runtime-legacy/samples/props-reactive-destroy/_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,10 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
test({ assert, logs, target }) { | ||
target.querySelector('button')?.click(); | ||
flushSync(); | ||
assert.deepEqual(logs, ['should fire once']); | ||
} | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/svelte/tests/runtime-legacy/samples/props-reactive-destroy/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,17 @@ | ||
<script> | ||
import Child from './Child.svelte'; | ||
let active = true; | ||
let data = { example: 'This is some example data' }; | ||
function log(data) { | ||
console.log('should fire once'); | ||
return data; | ||
} | ||
</script> | ||
|
||
<button on:click={() => active = false}>Hide</button> | ||
|
||
{#if active} | ||
<Child data={log(data)} /> | ||
{/if} |
11 changes: 11 additions & 0 deletions
11
packages/svelte/tests/runtime-runes/samples/props-reactive-destroy/Child.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 { onDestroy } from 'svelte'; | ||
const { data = 123 } = $props(); | ||
onDestroy(() => { | ||
data; | ||
}); | ||
</script> | ||
|
||
{data ? '' : null} |
10 changes: 10 additions & 0 deletions
10
packages/svelte/tests/runtime-runes/samples/props-reactive-destroy/_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,10 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
test({ assert, logs, target }) { | ||
target.querySelector('button')?.click(); | ||
flushSync(); | ||
assert.deepEqual(logs, ['should fire once']); | ||
} | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/svelte/tests/runtime-runes/samples/props-reactive-destroy/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,17 @@ | ||
<script> | ||
import Child from './Child.svelte'; | ||
let active = $state(true); | ||
let data = $state({ example: 'This is some example data' }); | ||
function log(data) { | ||
console.log('should fire once'); | ||
return data; | ||
} | ||
</script> | ||
|
||
<button onclick={() => (active = false)}>Hide</button> | ||
|
||
{#if active} | ||
<Child data={log(data)} /> | ||
{/if} |