Skip to content

Commit 92408e1

Browse files
authored
fix: get spread + bind working (#10091)
fixes #10033
1 parent 6acf7f3 commit 92408e1

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

.changeset/stale-books-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: take into account setters when spreading and binding

packages/svelte/src/internal/client/render.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,8 +2646,13 @@ const spread_props_handler = {
26462646
if (typeof p === 'object' && p !== null && key in p) return p[key];
26472647
}
26482648
},
2649-
getOwnPropertyDescriptor() {
2650-
return { enumerable: true, configurable: true };
2649+
getOwnPropertyDescriptor(target, key) {
2650+
let i = target.props.length;
2651+
while (i--) {
2652+
let p = target.props[i];
2653+
if (is_function(p)) p = p();
2654+
if (typeof p === 'object' && p !== null && key in p) return get_descriptor(p, key);
2655+
}
26512656
},
26522657
has(target, key) {
26532658
for (let p of target.props) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<button class="foo">0</button><button class="foo">0</button>`,
5+
6+
async test({ assert, target }) {
7+
const [btn1, btn2] = target.querySelectorAll('button');
8+
9+
await btn1?.click();
10+
assert.htmlEqual(
11+
target.innerHTML,
12+
`<button class="foo">1</button><button class="foo">1</button>`
13+
);
14+
15+
await btn2?.click();
16+
assert.htmlEqual(
17+
target.innerHTML,
18+
`<button class="foo">2</button><button class="foo">2</button>`
19+
);
20+
}
21+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
let { value, ...props } = $props();
3+
4+
</script>
5+
6+
<button {...props} onclick={() => value++}>{value}</button>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Button from './button.svelte';
3+
4+
let value = $state(0);
5+
6+
const props = {
7+
class: 'foo'
8+
};
9+
</script>
10+
11+
<Button {...props} bind:value />
12+
<button {...props} onclick={() => value++}>{value}</button>

0 commit comments

Comments
 (0)