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

Second-level function not doing reactive update #14755

Closed
hykilpikonna opened this issue Dec 18, 2024 · 6 comments
Closed

Second-level function not doing reactive update #14755

hykilpikonna opened this issue Dec 18, 2024 · 6 comments

Comments

@hykilpikonna
Copy link

Describe the bug

Second-level function updates are not triggering reactive update, as it's not wrapped with $.mutate by the compiler. Is there a way to manually do $.mutate?

<script lang="ts">
  let obj = {count: 0}	
  const increment = () => obj.count++
	const helper = (o) => o.count++
</script>

<div>count is {obj.count}</div>

<button onclick={increment}>+1</button>
<button onclick={() => helper(obj)}>+1</button>

image

Reproduction

https://svelte.dev/playground/19fcb36153b84f83b83fb9ba92b38463?version=5.14.4

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 7840HS with Radeon 780M Graphics
    Memory: 3.75 GB / 27.69 GB
  Binaries:
    Node: 22.5.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
    bun: 1.1.38 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527

Severity

annoyance

@webJose
Copy link
Contributor

webJose commented Dec 18, 2024

Are you intentionally staying in Svelte v4?

@hykilpikonna
Copy link
Author

Are you intentionally staying in Svelte v4?

Yes, see this issue for my issue with Svelte 5 Runes: #14754

@webJose
Copy link
Contributor

webJose commented Dec 18, 2024

I see. Ok, in this case, what you present here is Svelte v4's inability to refactor things in a nice way, and one of the main drivers for signals (runes). Generally speaking, what you want is not possible.

Maybe some son of a gun like a core team member could help you further here, so I'll just shut up now since I have no solutions for you.

@paoloricciuti
Copy link
Member

Yup this is just how svelte 4 works and one of the main reasons why svelte 5 is a rewrite. Thanks for reporting but I'm gonna close this

@paoloricciuti paoloricciuti closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
@webJose
Copy link
Contributor

webJose commented Dec 18, 2024

BTW, if PR #14639 is released, you could pair it with alien-signals or similar. Maybe that way you could achieve your goal.

@hykilpikonna
Copy link
Author

Yup this is just how svelte 4 works and one of the main reasons why svelte 5 is a rewrite. Thanks for reporting but I'm gonna close this

It would be nice to have a way to manually trigger or wrap $.mutate in a function...

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

3 participants