Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: handle reassignment of `$$props` and `$$restProps` Some libraries assign to properties of `$$props` and `$$restProps`. These were previously resulting in an error but are now handled properly #10359 (comment) * $$props is coarse grained on updates, so we can simplify this * fix * fix comment
- Loading branch information
1 parent
5e0845f
commit 2754e4e
Showing
12 changed files
with
177 additions
and
12 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: handle reassignment of `$$props` and `$$restProps` |
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
6 changes: 6 additions & 0 deletions
6
packages/svelte/tests/runtime-legacy/samples/props-reassign/App.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,6 @@ | ||
<script> | ||
$: $$props.a = $$props.a * 2; | ||
</script> | ||
|
||
<p>{$$props.a} {$$props.b}</p> | ||
<button on:click={() => $$props.b = 'b'}>update</button> |
35 changes: 35 additions & 0 deletions
35
packages/svelte/tests/runtime-legacy/samples/props-reassign/_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,35 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: ` | ||
<button>increment</button> | ||
<p>0 </p> | ||
<button>update</button> | ||
`, | ||
|
||
async test({ assert, target }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
|
||
await btn1.click(); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>increment</button> | ||
<p>2 </p> | ||
<button>update</button> | ||
` | ||
); | ||
|
||
await btn2.click(); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>increment</button> | ||
<p>4 b</p> | ||
<button>update</button> | ||
` | ||
); | ||
} | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/svelte/tests/runtime-legacy/samples/props-reassign/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,7 @@ | ||
<script> | ||
import App from './App.svelte'; | ||
let a = 0; | ||
</script> | ||
|
||
<button on:click={() => a++}>increment</button> | ||
<App {a} /> |
6 changes: 6 additions & 0 deletions
6
packages/svelte/tests/runtime-legacy/samples/rest-props-reassign/App.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,6 @@ | ||
<script> | ||
$: $$restProps.c = $$restProps.c ?? 'c'; | ||
</script> | ||
<p>{$$restProps.a} {$$restProps.b} {$$restProps.c}</p> | ||
<button on:click={() => $$restProps.b = 'b'}>update</button> |
35 changes: 35 additions & 0 deletions
35
packages/svelte/tests/runtime-legacy/samples/rest-props-reassign/_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,35 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: ` | ||
<button>increment</button> | ||
<p>0 c</p> | ||
<button>update</button> | ||
`, | ||
|
||
async test({ assert, target }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
|
||
await btn1.click(); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>increment</button> | ||
<p>1 c</p> | ||
<button>update</button> | ||
` | ||
); | ||
|
||
await btn2.click(); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<button>increment</button> | ||
<p>1 b c</p> | ||
<button>update</button> | ||
` | ||
); | ||
} | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/svelte/tests/runtime-legacy/samples/rest-props-reassign/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,7 @@ | ||
<script> | ||
import App from './App.svelte'; | ||
let a = 0; | ||
</script> | ||
|
||
<button on:click={() => a++}>increment</button> | ||
<App {a} /> |