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

Unexpected behavior with reactive statements #7154

Closed
jmroon opened this issue Jan 16, 2022 · 3 comments
Closed

Unexpected behavior with reactive statements #7154

jmroon opened this issue Jan 16, 2022 · 3 comments

Comments

@jmroon
Copy link

jmroon commented Jan 16, 2022

Describe the bug

The docs state that reactive assignments only trigger when values they depend on have changed. However this does not appear to be the case. Reactive assignments seem to trigger unexpectedly.

This has cropped up in particular when trying to create a copy of a store object when the store changes (which is a common use case with forms where you don't want to mutate the global store until the form is saved).

So far, the only surefire solution appears to be to subscribe to the store manually, as reactive assignments all appear to trigger unexpectedly.

Reproduction

https://svelte.dev/repl/6ffc787bb6fd42f1a2590b98ff8838cd?version=3.46.2

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 18.79 GB / 31.89 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.62)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    svelte: ^3.44.0 => 3.46.2

Severity

annoyance

@7nik
Copy link

7nik commented Jan 16, 2022

We've got a similar problem here #7129 (comment)

As a workaround, you can use setters in every affected reactive block instead of direct assignment.

let localForm = {};
const setLocalForm = (data) => { localForm = data; };
$: setLocalForm({...$formData});

@7nik
Copy link

7nik commented Jan 16, 2022

Duplicate of #4933

@jmroon
Copy link
Author

jmroon commented Jan 17, 2022

Indeed looks like this has been raised for a while now. Will close this and hope it gets addressed at some point.

@jmroon jmroon closed this as completed Jan 17, 2022
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

No branches or pull requests

2 participants