Skip to content

Commit 3d33ed9

Browse files
committed
fix: ensure bind:group works as intended with proxied state objects
1 parent 7bbaedd commit 3d33ed9

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

.changeset/giant-bags-wash.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: ensure bind:group works as intended with proxied state objects

packages/svelte/src/internal/client/dom/elements/bindings/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DEV } from 'esm-env';
22
import { render_effect, teardown } from '../../../reactivity/effects.js';
33
import { listen_to_event_and_reset_event } from './shared.js';
44
import * as e from '../../../errors.js';
5-
import { get_proxied_value, is } from '../../../proxy.js';
5+
import { is } from '../../../proxy.js';
66
import { queue_micro_task } from '../../task.js';
77
import { hydrating } from '../../hydration.js';
88
import { is_runes } from '../../../runtime.js';
@@ -126,7 +126,7 @@ export function bind_group(inputs, group_index, input, get, set = get) {
126126
if (is_checkbox) {
127127
value = value || [];
128128
// @ts-ignore
129-
input.checked = get_proxied_value(value).includes(get_proxied_value(input.__value));
129+
input.checked = value.includes(input.__value);
130130
} else {
131131
// @ts-ignore
132132
input.checked = is(input.__value, value);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
html: `<button>+</button><input type="checkbox" value="1"><input type="checkbox" value="2"><input type="checkbox" value="3">\n[]`,
6+
7+
test({ assert, target }) {
8+
const btn = target.querySelector('button');
9+
10+
btn?.click();
11+
flushSync();
12+
13+
assert.equal(target.querySelectorAll('input')[1].checked, true);
14+
assert.htmlEqual(
15+
target.innerHTML,
16+
`<button>+</button><input type="checkbox" value="1"><input type="checkbox" value="2"><input type="checkbox" value="3">\n["2"]`
17+
);
18+
}
19+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
let checkboxes = $state([]);
3+
let values = ['1', '2', '3'];
4+
</script>
5+
6+
<button onclick={() => checkboxes.push('2')}>+</button>
7+
8+
{#each values as val, i}
9+
<input type="checkbox" value={val} bind:group={checkboxes} />
10+
{/each}
11+
12+
{JSON.stringify(checkboxes)}

0 commit comments

Comments
 (0)