-
-
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: svelte:component evaluates props once (#8946)
Fixes #6634
- Loading branch information
Showing
6 changed files
with
56 additions
and
5 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 `svelte:component` evaluates props once |
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
5 changes: 5 additions & 0 deletions
5
packages/svelte/test/runtime/samples/dynamic-component-evals-props-once/Comp1.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,5 @@ | ||
<script> | ||
export let value; | ||
</script> | ||
|
||
<p>value(1) = {value}</p> |
5 changes: 5 additions & 0 deletions
5
packages/svelte/test/runtime/samples/dynamic-component-evals-props-once/Comp2.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,5 @@ | ||
<script> | ||
export let value; | ||
</script> | ||
|
||
<p>value(2) = {value}</p> |
28 changes: 28 additions & 0 deletions
28
packages/svelte/test/runtime/samples/dynamic-component-evals-props-once/_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,28 @@ | ||
export default { | ||
html: ` | ||
<p>value(1) = 1</p> | ||
<button>Toggle Component</button> | ||
`, | ||
|
||
async test({ assert, component, window, target }) { | ||
const button = target.querySelector('button'); | ||
await button.dispatchEvent(new window.Event('click')); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<p>value(2) = 2</p> | ||
<button>Toggle Component</button> | ||
` | ||
); | ||
assert.equal(component.n, 2); | ||
await button.dispatchEvent(new window.Event('click')); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<p>value(1) = 3</p> | ||
<button>Toggle Component</button> | ||
` | ||
); | ||
assert.equal(component.n, 3); | ||
} | ||
}; |
12 changes: 12 additions & 0 deletions
12
packages/svelte/test/runtime/samples/dynamic-component-evals-props-once/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,12 @@ | ||
<script> | ||
import Comp1 from './Comp1.svelte'; | ||
import Comp2 from './Comp2.svelte'; | ||
export let n = 0; | ||
let view = { comp: Comp1, fn: () => ++n }; | ||
</script> | ||
|
||
<svelte:component this={view.comp} value={view.fn()}/> | ||
|
||
<button on:click={e => view.comp = view.comp === Comp1 ? Comp2 : Comp1}>Toggle Component</button> | ||
|