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

Two way binding triggers reactivity twice #6685

Closed
ruslan-khomiak opened this issue Aug 26, 2021 · 4 comments
Closed

Two way binding triggers reactivity twice #6685

ruslan-khomiak opened this issue Aug 26, 2021 · 4 comments
Labels
bug compiler Changes relating to the compiler

Comments

@ruslan-khomiak
Copy link

Describe the bug

When the application is first launched, binding of non-primitive types is triggered twice

Reproduction

https://svelte.dev/repl/4a49ea25eca94484974c2f4c0f3d294b?version=3.42.3

Logs

No response

System Info

System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 2.11 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 15.9.0 - /usr/local/bin/node
    npm: 7.5.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 92.0.4515.159
    Edge: 92.0.902.78
    Firefox: 90.0.2
    Safari: 13.1.2
  npmPackages:
    svelte: ^3.40.0 => 3.40.1 
    webpack: ^5.46.0 => 5.46.0

Severity

annoyance

@dummdidumm
Copy link
Member

The underlying reason might be the same as for #6016

@dummdidumm dummdidumm added bug compiler Changes relating to the compiler labels Aug 26, 2021
@Prinzhorn
Copy link
Contributor

We have recently collected a couple of duplicates here #6590

@dummdidumm
Copy link
Member

Thanks for pointing that out. Closing as duplicate of #5689

@RaiVaibhav
Copy link
Contributor

RaiVaibhav commented Oct 19, 2021

Hey @dummdidumm summary of what I found, this issue is quite similar #6590 and the reason is because of the two-way binding, so for case like bind:clientwidth reactive will retrigger but for case where parent state bind with child state like in #5689 but it values is not getting changed then, svelte, not able to figure out whether to re-trigger or not, it's simply re-trigger every time.
besides this, #5689 is different from above and the reason is because of the conditional check not_equal($$.ctx[i], $$.ctx[i] = value) and when value is {} it makes the component dirty comparatively to when value is of primitive data type and there is one more point I didn't understand if (ready) make_dirty(component, i); so in the #5689 there a state change inside the reactive and svelte wait for its first reactive update till then it's ready, but what if there is state change inside the first reactive update.

I have opened the PR for fixing the beforeUpdate part.

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

No branches or pull requests

4 participants