Skip to content

Commit

Permalink
fix: add atoms to pending during restore
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunvegda committed May 20, 2024
1 parent 43a2416 commit 4d2e949
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/vanilla/store2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,15 @@ export const createStore = (): Store => {
const pendingPair = createPending()
for (const [atom, value] of values) {
if (hasInitialValue(atom)) {
setAtomStateValueOrPromise(atom, getAtomState(atom), value)
recomputeDependents(pendingPair, atom)
const aState = getAtomState(atom)
const hasPrevValue = 'v' in aState
const prevValue = aState.v
setAtomStateValueOrPromise(atom, aState, value)
mountDependencies(pendingPair, atom, aState)
if (!hasPrevValue || !Object.is(prevValue, aState.v)) {
addPendingAtom(pendingPair, atom, aState)
recomputeDependents(pendingPair, atom)
}
}
}
flushPending(pendingPair)
Expand Down

0 comments on commit 4d2e949

Please sign in to comment.