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

Svelte 5: optimise prop access #11055

Closed
Rich-Harris opened this issue Apr 3, 2024 · 0 comments · Fixed by #12201
Closed

Svelte 5: optimise prop access #11055

Rich-Harris opened this issue Apr 3, 2024 · 0 comments · Fixed by #12201
Milestone

Comments

@Rich-Harris
Copy link
Member

Describe the problem

A component author might choose to use rest props as an authoring convenience:

<script>
-  let { a, b } = $props();
+  let { ...props } = $props();
</script>

-<p>{a} + {b} = {a + b}</p>
+<p>{props.a} + {props.b} = {props.a + props.b}</p>

It's not the pattern we promote (you can't specify fallback values or bindability), but it's a valid choice. Right now, this creates a rest_props proxy, even though it's not strictly necessary in this component:

let props = $.rest_props($$props, []);

Describe the proposed solution

If the only times props is referenced is in a non-computed member expression, we can skip the rest_props call and treat props.a as though there were a named a prop.

Importance

nice to have

@Rich-Harris Rich-Harris added this to the 5.0 milestone Apr 3, 2024
dummdidumm added a commit that referenced this issue Jun 27, 2024
- allow to write `let props = $props()`
- optimize read access of props.x to use `$$props` argument directly; closes #11055
dummdidumm added a commit that referenced this issue Jun 27, 2024
- allow to write `let props = $props()`
- optimize read access of props.x to use `$$props` argument directly; closes #11055
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant