Skip to content
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

docs: order of attribute and props matter #15509

Open
sacrosanctic opened this issue Mar 14, 2025 · 3 comments
Open

docs: order of attribute and props matter #15509

sacrosanctic opened this issue Mar 14, 2025 · 3 comments

Comments

@sacrosanctic
Copy link
Contributor

Describe the bug

<input
  {...rest}
  type="text"
/>
<input
  type="text"
  {...rest}
/>

These do not produce the same results and I don't see it documented in https://svelte.dev/docs/svelte/basic-markup or https://svelte.dev/docs/svelte/$props#Rest-props

I'm propose adding it to basic-markup and that addresses both elements and components.

Reproduction

REPL

Logs

System Info

.

Severity

annoyance

@paoloricciuti
Copy link
Member

I think it is pretty intuitive but I'm not opposed to add a section to the docs

@sacrosanctic
Copy link
Contributor Author

In vanilla HTML, the ordering does not matter. So it can be a hidden gotcha.

@7nik
Copy link
Contributor

7nik commented Mar 15, 2025

In vanilla JS, the ordering does matter. So it isn't so hidden.

let obj = { foo: 42 };
let a = {
  foo: 123,
  ...obj,
};
let b = {
  ...obj,
  foo: 123,
};

a and b will have different values in foo and the same applies to props.
But, yeah, there is nothing bad in reminding it in the docs and/or tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants