Skip to content

chore: use proxies instead of signals for spread/rest props #9801

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 15 commits into from
Dec 6, 2023

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Dec 6, 2023

Continuation of #9799.

As well as simplifying things internally (yes, it's more code, though I expect it to allow us to delete code in future, hopefully including is_signal which is brittle and ideally wouldn't be necessary), this makes spread/rest props fine-grained in a way that wasn't previously possible.

As an illustration, consider this case:

<script>
	import Child from './Child.svelte';

	let x = $state(0);
	let y = $state(0);
</script>
 
<svelte:window onmousemove={(e) => {
	x = e.clientX;
	y = e.clientY;
}} />

<Child {...{ x, y }} message="hello" />
<script>
	let { ...stuff } = $props();

	function evaluate(value) {
		console.log('evaluating', value);
		return value;
	}
</script>

<p>{evaluate(stuff.message)}</p>

The text effect that renders stuff.message is re-run on every mousemove event even though it's clearly static. On this branch, that doesn't happen.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Dec 6, 2023

⚠️ No Changeset found

Latest commit: 92f2c8b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Dec 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svelte-5-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 6, 2023 9:04am

@Rich-Harris
Copy link
Member Author

As a result of this PR, the only place we call unwrap is inside each item blocks. That, and bind:this (which feels like an anomaly) are the only places left that deal with the MaybeSignal type

@Rich-Harris Rich-Harris marked this pull request as ready for review December 6, 2023 04:46
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes make sense to me 👍 The one caveat is that this iterates over the spread array on each invocation, compared to on each change to the spread before. But since that spread array (the $.spread_array(() => { dynamic: .. }, { static: .. }, ..)) is only one or two elements in the common case it doesn't matter in practise.

@dummdidumm dummdidumm merged commit fc9776b into simplify-props-3 Dec 6, 2023
@dummdidumm dummdidumm deleted the simplify-props-4 branch December 6, 2023 09:08
Rich-Harris added a commit that referenced this pull request Dec 6, 2023
* use proxy instead of signal in createRoot

* DRY

* remove for now

* lint

* chore: use proxies instead of signals for spread/rest props (#9801)

* use proxies instead of signals for spread/rest

* fix some spread attribute stuff

* remove is_signal calls

* simplify some more

* more

* remove some unnecessary unwrapping

* another

* simplify

* simplify

* simplify

* remove another MaybeSignal

* more

* remove more unwraps

* code-golf, docs

---------

Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Simon Holthausen <[email protected]>

* add missing jsdoc annotation

---------

Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Simon Holthausen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants