facebookexperimental/Recoil

useRecoilCallback batched set calls update state incorrectly

Open

#1935 aperta il 5 ago 2022

Vedi su GitHub
 (14 commenti) (0 reazioni) (0 assegnatari)JavaScript (1151 fork)batch import
bughelp wanted

Metriche repository

Star
 (19.428 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

We've been using Recoil quite extensively and believe we have encountered a bug with useRecoilCallback and state updating.

There is a rootState atom that we want to update via a useRecoilCallback that contains multiple set calls. If the set calls within useRecoilCallback try to set the recoil state of rootState directly or through a single selector layer, the final rootState is as expected. However, if there is more than one layer of selector dependencies, it is only the last set that has a result on rootState.

Here is the CodeSandbox.

Expected: All steps change their state from ['1', '2', '3'] to ['one', 'two', 'three'] Result: The only step changing the state is the last one for which set has run. In effect: ['1', '2', '3'] changes to ['1', '2', 'three']

Guida contributor