solidjs / solidjs/solid

Reverting values to their previously committed value before Reactivity propagates still triggers recomputation

Open
#1,421 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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
  1. Go to the playground link
  2. Switch to the Console output in dev tools
  3. Click the 'Click' button
  4. Despite the final value of num() being unchanged at the end of batch(...), the effect is run, and the "new" value of num() 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.