-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: better binding interop between runes/non-runes components #12123
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
48eef0d
Ensure binding from legacy component passed to runes component update…
dummdidumm 82f47f3
fix adjacent bug around wrong value getting return upon mutation
dummdidumm dbeb21c
deduplicate
dummdidumm c8c8042
changeset
dummdidumm 3154319
simplify
dummdidumm 298160d
move comment
dummdidumm 5415cc5
rename
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 | ||
--- | ||
|
||
fix: better binding interop between runes/non-runes components |
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
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
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
8 changes: 8 additions & 0 deletions
8
packages/svelte/tests/runtime-legacy/samples/mutation-correct-return-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,8 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
mode: ['client'], | ||
test({ assert, logs }) { | ||
assert.deepEqual(logs, [true]); | ||
} | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/svelte/tests/runtime-legacy/samples/mutation-correct-return-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,4 @@ | ||
<script> | ||
export let a = {}; | ||
console.log((a.b = true)); | ||
</script> |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/runtime-runes/samples/binding-interop/Component1.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,9 @@ | ||
<script> | ||
let { object = $bindable(), primitive = $bindable() } = $props(); | ||
</script> | ||
|
||
{#if primitive} | ||
<button onclick={() => (primitive = 'bar')}>{primitive}</button> | ||
{:else} | ||
<button onclick={() => (object.value = 'bar')}>{object.value}</button> | ||
{/if} |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/runtime-runes/samples/binding-interop/Component2.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,9 @@ | ||
<script> | ||
let { object = $bindable({}), primitive = $bindable('') } = $props(); | ||
</script> | ||
|
||
{#if primitive} | ||
<button onclick={() => (primitive = 'bar')}>{primitive}</button> | ||
{:else} | ||
<button onclick={() => (object.value = 'bar')}>{object.value}</button> | ||
{/if} |
24 changes: 24 additions & 0 deletions
24
packages/svelte/tests/runtime-runes/samples/binding-interop/Legacy.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,24 @@ | ||
<svelte:options runes={false} /> | ||
|
||
<script> | ||
import Component1 from './Component1.svelte'; | ||
import Component2 from './Component2.svelte'; | ||
|
||
let object1 = { value: 'foo' }; | ||
let object2 = { value: 'foo' }; | ||
|
||
let primitive1 = 'foo'; | ||
let primitive2 = 'foo'; | ||
</script> | ||
|
||
{object1.value} | ||
<Component1 bind:object={object1} /> | ||
|
||
{object2.value} | ||
<Component2 bind:object={object2} /> | ||
|
||
{primitive1} | ||
<Component1 bind:primitive={primitive1} /> | ||
|
||
{primitive2} | ||
<Component2 bind:primitive={primitive2} /> |
39 changes: 39 additions & 0 deletions
39
packages/svelte/tests/runtime-runes/samples/binding-interop/Runes.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,39 @@ | ||
<script> | ||
import Component1 from './Component1.svelte'; | ||
import Component2 from './Component2.svelte'; | ||
|
||
let object1 = $state({ value: 'foo' }); | ||
let object2 = $state({ value: 'foo' }); | ||
|
||
class Frozen { | ||
constructor(value) { | ||
this.value = value; | ||
} | ||
} | ||
let object3 = $state(new Frozen('foo')); | ||
let object4 = $state(new Frozen('foo')); | ||
|
||
let primitive1 = $state('foo'); | ||
let primitive2 = $state('foo'); | ||
</script> | ||
|
||
{object1.value} | ||
<Component1 bind:object={object1} /> | ||
|
||
{object2.value} | ||
<Component2 bind:object={object2} /> | ||
|
||
<!-- force them into a different render effect so they don't coincidently update with the others --> | ||
{#if true} | ||
{object3.value} | ||
<Component1 bind:object={object3} /> | ||
|
||
{object4.value} | ||
<Component2 bind:object={object4} /> | ||
{/if} | ||
|
||
{primitive1} | ||
<Component1 bind:primitive={primitive1} /> | ||
|
||
{primitive2} | ||
<Component2 bind:primitive={primitive2} /> |
24 changes: 24 additions & 0 deletions
24
packages/svelte/tests/runtime-runes/samples/binding-interop/_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,24 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
mode: ['client'], | ||
async test({ assert, target }) { | ||
const buttons = target.querySelectorAll('button'); | ||
|
||
for (const button of buttons) { | ||
await button.click(); | ||
flushSync(); | ||
} | ||
flushSync(); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
bar <button>bar</button> bar <button>bar</button> bar <button>bar</button> bar <button>bar</button> | ||
<hr> | ||
bar <button>bar</button> bar <button>bar</button> foo <button>foo</button> foo <button>foo</button> bar <button>bar</button> bar <button>bar</button> | ||
` | ||
); | ||
} | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/svelte/tests/runtime-runes/samples/binding-interop/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,10 @@ | ||
<script> | ||
import Legacy from './Legacy.svelte'; | ||
import Runes from './Runes.svelte'; | ||
</script> | ||
|
||
<Legacy /> | ||
|
||
<hr /> | ||
|
||
<Runes /> |
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
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.
Uh oh!
There was an error while loading. Please reload this page.