-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
fix: better interop of $state
with actions/$:
statements
#10543
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8b75fa
fix: better interop of `$state` with actions/`$:` statements
dummdidumm 45f6c11
fix test, add comment
dummdidumm 9b6d41b
fix
dummdidumm c1e5eea
no longer needed
dummdidumm e94df0f
tweak test which would've caught my bug
dummdidumm 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 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 update methods of actions and reactive statements work with fine-grained `$state` |
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
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
24 changes: 24 additions & 0 deletions
24
packages/svelte/tests/runtime-runes/samples/action-state-arg/_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,24 @@ | ||
import { test } from '../../test'; | ||
import { tick } from 'svelte'; | ||
|
||
export default test({ | ||
html: `<button>reassign</button><button>mutate</button><div>0</div>`, | ||
|
||
async test({ assert, target }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
|
||
btn1.click(); | ||
await tick(); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
`<button>reassign</button><button>mutate</button><div>1</div>` | ||
); | ||
|
||
btn2.click(); | ||
await tick(); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
`<button>reassign</button><button>mutate</button><div>2</div>` | ||
); | ||
} | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/svelte/tests/runtime-runes/samples/action-state-arg/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,16 @@ | ||
<script> | ||
let foo = $state({ count: 0 }); | ||
let count = $state(0); | ||
|
||
function action() { | ||
return { | ||
update(foo) { | ||
count = foo.count; | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<button onclick={() => foo = {...foo, count: foo.count + 1 }}>reassign</button> | ||
<button onclick={() => foo.count++}>mutate</button> | ||
<div use:action={foo}>{count}</div> |
24 changes: 24 additions & 0 deletions
24
packages/svelte/tests/runtime-runes/samples/fine-grained-prop-reactive-statement/_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,24 @@ | ||
import { test } from '../../test'; | ||
import { tick } from 'svelte'; | ||
|
||
export default test({ | ||
html: `<button>reassign</button><button>mutate</button><p>0 / 0</p>`, | ||
|
||
async test({ assert, target }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
|
||
btn1.click(); | ||
await tick(); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
`<button>reassign</button><button>mutate</button><p>1 / 1</p>` | ||
); | ||
|
||
btn2.click(); | ||
await tick(); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
`<button>reassign</button><button>mutate</button><p>2 / 2</p>` | ||
); | ||
} | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/runtime-runes/samples/fine-grained-prop-reactive-statement/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,9 @@ | ||
<script> | ||
import Old from './old.svelte'; | ||
|
||
let prop = $state({ count: 0 }); | ||
</script> | ||
|
||
<button onclick={() => prop = {...prop, count: prop.count + 1 }}>reassign</button> | ||
<button onclick={() => prop.count++}>mutate</button> | ||
<Old {prop}></Old> |
11 changes: 11 additions & 0 deletions
11
packages/svelte/tests/runtime-runes/samples/fine-grained-prop-reactive-statement/old.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 @@ | ||
<svelte:options runes={false} /> | ||
<script> | ||
export let prop; | ||
let count_1 = prop.count; | ||
$: { | ||
count_1 = prop.count; | ||
} | ||
$: count_2 = prop.count; | ||
</script> | ||
|
||
<p>{count_1} / {count_2}</p> |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is from #8992 and was (turns out, wrongfully) changed when moving to proxies in #9826 . This uncovered that using
$.proxy
insidesvelte/legacy
could also have caused these kinds of problems this PR fixes in some situations, but it shouldn't matter anymore now that deeply reactive state is properly handled in the places where it matters.