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 on $$props/$$restProps optimisation are vague #8249

Open
brunnerh opened this issue Feb 4, 2023 · 2 comments
Open

Docs on $$props/$$restProps optimisation are vague #8249

brunnerh opened this issue Feb 4, 2023 · 2 comments

Comments

@brunnerh
Copy link
Member

brunnerh commented Feb 4, 2023

Describe the bug

The docs state:

$$props references all props that are passed to a component, including ones that are not declared with export. It is not generally recommended, as it is difficult for Svelte to optimise.

$$restProps contains only the props which are not declared with export. It can be used to pass down other unknown attributes to an element in a component. It shares the same optimisation problems as $$props, and is likewise not recommended.

What exactly does that mean?
What are the consequences to expect?
Does the type of usage matter, e.g. $$props.something in JS vs <element {...$$props} />?

For $$restProps, would it be better to collect additional data in a single property when used in a spread?

<element {...$$restProps} />
vs
<script>export let attributes;</script>
<element {...attributes} />

Reproduction

N/A

Logs

No response

System Info

-

Severity

annoyance

@gregg-cbs
Copy link

To add to this its not clear how to forward events seeing as $$restProps does not include events how do you bind all incoming events?

<button {...$$restProps} on:{incomingEvents}/>

@brunnerh
Copy link
Member Author

brunnerh commented Jan 8, 2024

That was just not possible in v3/4 and will be possible in Svelte 5 (events will just be callbacks that are spread together with other props).

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

3 participants