-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: re-evaluate derived props during teardown #16278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
42f5d10
Store deriveds old value before updating them for consistency with di…
raythurnvoid 1fc9f08
Add tests for derived old values in teardown functions
raythurnvoid 9d9b64b
Add tests for props old values in onDestroy hooks to prevent regressions
raythurnvoid 5ed74b2
Add changeset
raythurnvoid b213de2
Update comment
raythurnvoid 562c9e3
remove extraneous tests - these pass with or without the src change
Rich-Harris 85268bc
revert
Rich-Harris 0ad9588
WIP
Rich-Harris 8a6d5ed
simplify props
Rich-Harris e0ebcc8
simplify
Rich-Harris 9506889
tweak
Rich-Harris 2a16f17
reorder a bit
Rich-Harris b141f60
simplify
Rich-Harris ab1ea27
unused
Rich-Harris bdd5897
more
Rich-Harris 1253886
more
Rich-Harris c9cf7e3
tweak
Rich-Harris 73d66a8
also appears to be unnecessary
Rich-Harris dfbce4d
changeset
Rich-Harris 29cfec1
Merge branch 'simpler-props' into gh-16263
Rich-Harris 884d431
fix
Rich-Harris 5083231
merge main
Rich-Harris 809693c
Update .changeset/light-rivers-jump.md
Rich-Harris f32818c
easier debugging
Rich-Harris 4a89898
fix
Rich-Harris 79e7203
Merge branch 'gh-16263' of github.com:sveltejs/svelte into gh-16263
Rich-Harris 05636d3
WIP
Rich-Harris c8ab9e6
fix
Rich-Harris 99f0464
merge
Rich-Harris cff7ed6
merge main
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||
--- | ||
|
||
Store deriveds old value before updating them for consistency with directly assigned sources when reading in teardown functions | ||
This file contains hidden or 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 hidden or 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
22 changes: 22 additions & 0 deletions
22
packages/svelte/tests/runtime-runes/samples/derived-cleanup-old-value/_config.js
This file contains hidden or 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,22 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
async test({ assert, logs, target }) { | ||
const [increment] = target.querySelectorAll('button'); | ||
|
||
flushSync(() => increment.click()); | ||
flushSync(() => increment.click()); | ||
flushSync(() => increment.click()); | ||
|
||
assert.deepEqual(logs, [ | ||
'count: 1', | ||
'squared: 1', | ||
'count: 2', | ||
'squared: 4', | ||
'count: 3', | ||
'squared: 9', | ||
'count: 4' | ||
]); | ||
} | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/svelte/tests/runtime-runes/samples/derived-cleanup-old-value/main.svelte
This file contains hidden or 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 @@ | ||
<script> | ||
let count = $state(1); | ||
let squared = $derived(count * count); | ||
|
||
$effect(() => { | ||
console.log(`count: ${count}`); | ||
|
||
return () => { | ||
console.log(`squared: ${squared}`); | ||
}; | ||
}); | ||
</script> | ||
|
||
<button onclick={() => count++}>increment</button> | ||
|
||
<p>count: {count}</p> | ||
|
||
{#if count % 2 === 0} | ||
<p id="squared">squared: {squared}</p> | ||
{/if} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.