Skip to content

fix: exclude internal props from spread attributes #9384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-owls-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: exclude internal props from spread attributes
15 changes: 9 additions & 6 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -2844,14 +2844,12 @@ export function spread_attributes(dom, prev, attrs, css_hash) {

for (const key in next) {
let value = next[key];
if (has_hash && key === 'class') {
if (value) value += ' ';
value += css_hash;
}

if (value === prev?.[key]) continue;

if (key.startsWith('on')) {
const prefix = key.slice(0, 2);
if (prefix === '$$') continue;

if (prefix === 'on') {
// TODO delegate?
/** @type {{ capture?: true }} */
const opts = {};
Expand Down Expand Up @@ -2893,6 +2891,11 @@ export function spread_attributes(dom, prev, attrs, css_hash) {
dom[key] = value;
}
} else if (typeof value !== 'function') {
if (has_hash && key === 'class') {
if (value) value += ' ';
value += css_hash;
}

attr(dom, key, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let { ...stuff } = $props();
</script>

<button {...stuff} on:click>
<slot></slot>
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test } from '../../test';

export default test({
html: `<button>clicks: 0</button>`,

async test({ assert, target }) {
const button = target.querySelector('button');

button?.click();
await Promise.resolve();
assert.htmlEqual(target.innerHTML, '<button>clicks: 1</button>');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
import Button from './Button.svelte';

let count = $state(0);

function increment() {
count += 1;
}
</script>

<Button on:click={increment}>
clicks: {count}
</Button>