Reverting values to their previously committed value before Reactivity propagates still triggers recomputation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 36.1k
- Forks
- 1.1k
- Avg merge
- 9h 18m
- Merged PRs (30d)
- 195
Description
Describe the bug
Within a batch call, when setting a signal's value to a new value, and then back to the original value, effects are still run for the "changed" value.
This could be desired behavior, but I think an argument could be made for the behavior I'm expecting here.
The playground I've linked is a contrived example. I encountered this when trying to batch a couple store actions together, that involved this scenario of a value being changed, and then changed back to the original value at the start of the batch operation.
Your Example Website or App
https://playground.solidjs.com/anonymous/157e35f6-d812-4798-8222-082d559eec5f
Steps to Reproduce the Bug or Issue
- Go to the playground link
- Switch to the Console output in dev tools
- Click the 'Click' button
- Despite the final value of
num()being unchanged at the end ofbatch(...), the effect is run, and the "new" value ofnum()is logged to the console.memoNum()naturally does not have the same issue.
Expected behavior
I expect changes to signal values within batch to be "batched", with only the end result being considered in determining what changed and what effects to run. Note that when calling setNum(0) when num() is already 0, effects are not rerun.
Sorry I know this is probably an inaccurate expectation of what batch should do. The docs description doesn't make a lot of sense to me:
# batch
Holds executing downstream computations within the block until the end to prevent unnecessary recalculation. Solid Store's set method, Mutable Store's array methods, and Effects automatically wrap their code in a batch.
Screenshots or Videos
No response
Platform
N/A
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked Solid playground and tracing the batch call, signal updates, and effect output described in the reproduction steps. Compare the final signal value with the computations that run, then establish the intended behavior and add or update coverage for reverting a value within one batch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100