From a77c215c4832e224f236e36b52488cd70ca7cf63 Mon Sep 17 00:00:00 2001 From: k00b Date: Thu, 26 Dec 2024 19:51:55 -0600 Subject: [PATCH 1/2] fix 1695 by not updating ancestors on zap --- components/item-act.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/components/item-act.js b/components/item-act.js index 459fff7b7..609d785fb 100644 --- a/components/item-act.js +++ b/components/item-act.js @@ -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: { @@ -212,20 +212,22 @@ function modifyActCache (cache, { result, invoice }) { } }) - if (act === 'TIP') { - // update all ancestors - path.split('.').forEach(aId => { - if (Number(aId) === Number(id)) return - cache.modify({ - id: `Item:${aId}`, - fields: { - commentSats (existingCommentSats = 0) { - return existingCommentSats + sats - } - } - }) - }) - } + // removing this fixes issue #1695 because optimistically updating all ancestors + // conflicts with the writeQuery on navigation from SSR + // if (act === 'TIP') { + // // update all ancestors + // path.split('.').forEach(aId => { + // if (Number(aId) === Number(id)) return + // cache.modify({ + // id: `Item:${aId}`, + // fields: { + // commentSats (existingCommentSats = 0) { + // return existingCommentSats + sats + // } + // } + // }) + // }) + // } } export function useAct ({ query = ACT_MUTATION, ...options } = {}) { From 970f7411db4313c2937ab1165461df6cefd46532 Mon Sep 17 00:00:00 2001 From: k00b Date: Fri, 27 Dec 2024 10:17:56 -0600 Subject: [PATCH 2/2] update ancestors but only onPaid --- components/item-act.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/components/item-act.js b/components/item-act.js index 609d785fb..477cf459b 100644 --- a/components/item-act.js +++ b/components/item-act.js @@ -211,23 +211,27 @@ function modifyActCache (cache, { result, invoice }) { } } }) +} - // removing this fixes issue #1695 because optimistically updating all ancestors - // conflicts with the writeQuery on navigation from SSR - // if (act === 'TIP') { - // // update all ancestors - // path.split('.').forEach(aId => { - // if (Number(aId) === Number(id)) return - // cache.modify({ - // id: `Item:${aId}`, - // fields: { - // commentSats (existingCommentSats = 0) { - // return existingCommentSats + sats - // } - // } - // }) - // }) - // } +// 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 => { + if (Number(aId) === Number(id)) return + cache.modify({ + id: `Item:${aId}`, + fields: { + commentSats (existingCommentSats = 0) { + return existingCommentSats + sats + } + } + }) + }) + } } export function useAct ({ query = ACT_MUTATION, ...options } = {}) { @@ -261,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 }) } })