Skip to content

fix: improve props spreading logic #10574

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 1 commit into from
Feb 20, 2024
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/three-papayas-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: improve props spreading logic
9 changes: 1 addition & 8 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -2337,14 +2337,7 @@ const rest_props_handler = {
return key in target.props;
},
ownKeys(target) {
/** @type {Array<string | symbol>} */
const keys = [];

for (let key in target.props) {
if (!target.exclude.includes(key)) keys.push(key);
}

return keys;
return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
}
};

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

<button {...props}>
Hello world
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test } from '../../test';

export default test({
async test({ assert, target }) {
assert.htmlEqual(
target.innerHTML,
`<button data-attr="">Hello world</button><button data-attr="">Hello world</button>`
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script>
import Button from "./Button.svelte";

const attrs = {};

Object.defineProperty(attrs, "data-attr", {
value: "",
enumerable: true
});
</script>

<button {...attrs}>
Hello world
</button>

<Button {...attrs} />