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

Object destructed props did not match sometimes #2282

Closed
cvlab opened this issue Mar 20, 2019 · 2 comments
Closed

Object destructed props did not match sometimes #2282

cvlab opened this issue Mar 20, 2019 · 2 comments
Labels

Comments

@cvlab
Copy link
Contributor

cvlab commented Mar 20, 2019

v3.0.0-beta.20

Small bugs using object destructed dynamic props

<Component { ...{ b: 1 } } />
to
<Component { ...undefined } />
did not remove old prop

https://svelte.dev/repl/3757254ce74b375821ea525b818a5bc0?version=3.6.9

<Component { ...{ b: 1 } } />
to
<Component { ...{ } } />
did not remove b, b prop exists as undefined

https://svelte.dev/repl/431834e7d8d83e0634304572736621a6?version=3.6.9

@Rich-Harris
Copy link
Member

Simpler repro: https://svelte.dev/repl/08385b2631684133b6fc987a1be21606?version=3.8.1

What's happening here is that $$self.$set looks like this:

function instance($$self, $$props, $$invalidate) {
	$$self.$set = $$new_props => {
		$$invalidate('$$props', $$props = assign(assign({}, $$props), $$new_props))
	};

	return {
		$$props,
		$$props: $$props = exclude_internal_props($$props)
	};
}

(Unrelated to this bug, but $$props is being output twice in the instance context.)

In other words, new props are always merged with the old ones. Normally this works, and allows partial updates, because the list of prop names is the same. But in the case of spread props where the list of prop names is not the same, it results in this buggy behaviour.

@Conduitry
Copy link
Member

I don't think we want to consider the behavior beyond that which was fixed by #3306 a bug. Given a component instance, there is no way to unset a prop, even if spread props aren't involved at all. All you can do is set it to undefined. Closing, as the rest of this was fixed back in 3.12.0.

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

No branches or pull requests

3 participants