Skip to content

Commit 2aacfad

Browse files
authored
fix: exclude internal props from spread attributes (#9384)
* exclude internal props from spread attributes * changeset * tighten up --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 51394a4 commit 2aacfad

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

.changeset/moody-owls-cry.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: exclude internal props from spread attributes

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,14 +2844,12 @@ export function spread_attributes(dom, prev, attrs, css_hash) {
28442844

28452845
for (const key in next) {
28462846
let value = next[key];
2847-
if (has_hash && key === 'class') {
2848-
if (value) value += ' ';
2849-
value += css_hash;
2850-
}
2851-
28522847
if (value === prev?.[key]) continue;
28532848

2854-
if (key.startsWith('on')) {
2849+
const prefix = key.slice(0, 2);
2850+
if (prefix === '$$') continue;
2851+
2852+
if (prefix === 'on') {
28552853
// TODO delegate?
28562854
/** @type {{ capture?: true }} */
28572855
const opts = {};
@@ -2893,6 +2891,11 @@ export function spread_attributes(dom, prev, attrs, css_hash) {
28932891
dom[key] = value;
28942892
}
28952893
} else if (typeof value !== 'function') {
2894+
if (has_hash && key === 'class') {
2895+
if (value) value += ' ';
2896+
value += css_hash;
2897+
}
2898+
28962899
attr(dom, key, value);
28972900
}
28982901
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let { ...stuff } = $props();
3+
</script>
4+
5+
<button {...stuff} on:click>
6+
<slot></slot>
7+
</button>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<button>clicks: 0</button>`,
5+
6+
async test({ assert, target }) {
7+
const button = target.querySelector('button');
8+
9+
button?.click();
10+
await Promise.resolve();
11+
assert.htmlEqual(target.innerHTML, '<button>clicks: 1</button>');
12+
}
13+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import Button from './Button.svelte';
3+
4+
let count = $state(0);
5+
6+
function increment() {
7+
count += 1;
8+
}
9+
</script>
10+
11+
<Button on:click={increment}>
12+
clicks: {count}
13+
</Button>

0 commit comments

Comments
 (0)