sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.66k stars 4.13k forks source link

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

Open brunnerh opened 1 year ago

brunnerh commented 1 year ago

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 commented 9 months ago

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 commented 9 months ago

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).