fix 1695 by not updating ancestors on zap (#1766)

* fix 1695 by not updating ancestors on zap

* update ancestors but only onPaid
This commit is contained in:
Keyan 2024-12-27 10:19:49 -06:00 committed by GitHub
parent 6efa782c11
commit 18445b1dc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View File

@ -181,7 +181,7 @@ export default function ItemAct ({ onClose, item, act = 'TIP', step, children, a
function modifyActCache (cache, { result, invoice }) {
if (!result) return
const { id, sats, path, act } = result
const { id, sats, act } = result
cache.modify({
id: `Item:${id}`,
fields: {
@ -211,7 +211,13 @@ function modifyActCache (cache, { result, invoice }) {
}
}
})
}
// doing this onPaid fixes issue #1695 because optimistically updating all ancestors
// conflicts with the writeQuery on navigation from SSR
function updateAncestors (cache, { result, invoice }) {
if (!result) return
const { id, sats, act, path } = result
if (act === 'TIP') {
// update all ancestors
path.split('.').forEach(aId => {
@ -259,6 +265,7 @@ export function useAct ({ query = ACT_MUTATION, ...options } = {}) {
onPaid: (cache, { data }) => {
const response = getPaidActionResult(data)
if (!response) return
updateAncestors(cache, response)
options?.onPaid?.(cache, { data })
}
})