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

Update binding prop in component trigger twice reaction. #5144

Closed
dishuostec opened this issue Jul 14, 2020 · 8 comments
Closed

Update binding prop in component trigger twice reaction. #5144

dishuostec opened this issue Jul 14, 2020 · 8 comments
Labels

Comments

@dishuostec
Copy link

Describe the bug
When update binding prop within a component, reactive statement in parent component processed twice.

App.svelte

<script>
	import Foo from './Foo.svelte'
	let data;
	let count = 0;
	$: console.log('data', ++count, data);
</script>

<Foo bind:data={data} />
{count}

Foo.svelte

<script>
	export let data;
	data = {foo:null};
</script>

Logs

"data" 1 undefined
"data" 2 ▶ Object { foo: null }
"data" 3 ▶ Object { foo: null }

To Reproduce
It seems 3.16.5 introduced the bug.
https://svelte.dev/repl/b245bd85f01043e9b5c37270398f463c?version=3.16.5

3.16.4 is ok.
https://svelte.dev/repl/b245bd85f01043e9b5c37270398f463c?version=3.16.4

Expected behavior
Run reactive statement once.

@dishuostec dishuostec changed the title Update binding prop in component trigger twice update. Update binding prop in component trigger twice reaction. Jul 14, 2020
@antony
Copy link
Member

antony commented Jul 14, 2020

I'm not convinced this is a bug. By using ++count in your reactive statement, you are creating a reactive dependency on count, and also incrementing it once the statement is run. So the variable changes twice, from 0 to 1, and 1 to 2.

@antony antony added the awaiting submitter needs a reproduction, or clarification label Jul 14, 2020
@dishuostec
Copy link
Author

I removed count, it still processed twice.

@dishuostec
Copy link
Author

https://svelte.dev/repl/b245bd85f01043e9b5c37270398f463c?version=3.16.4

"data" undefined
"data" ▶ Object { foo: null }

and https://svelte.dev/repl/b245bd85f01043e9b5c37270398f463c?version=3.16.5

"data" undefined
2x "data" ▶ Object { foo: null }

@tanhauhau
Copy link
Member

Haven't take a deep look, but probably related to #3180

@antony
Copy link
Member

antony commented Jul 14, 2020

@dishuostec thanks - that's a bit clearer now.

#3180 relates to stores, but if there is some shared logic there, then it makes sense that it might be the same root cause.

@antony antony added bug and removed awaiting submitter needs a reproduction, or clarification labels Jul 14, 2020
@Conduitry
Copy link
Member

@pwwang
Copy link

pwwang commented Aug 13, 2020

This is not fixed when the binding prop is used as an argument of a function:

https://svelte.dev/repl/5b37ba40c8854d86a9dab9ace0b6b861?version=3.24.1

@pzeinlinger
Copy link

@Conduitry I can confirm it's not fixed in 3.29.7 when binding prop is used as an argument as @pwwang states.

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

7 participants