facebookexperimental/Recoil

useRecoilCallback batched set calls update state incorrectly

オープン

#1,935 opened on 2022/08/05

 (14 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (1,151 件のフォーク)batch import
bughelp wanted

Repository metrics

Stars
 (19,428 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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']

コントリビューターガイド