From 18445b1dc1649e782091744a29d8147adaf20435 Mon Sep 17 00:00:00 2001 From: Keyan <34140557+huumn@users.noreply.github.com> Date: Fri, 27 Dec 2024 10:19:49 -0600 Subject: [PATCH] fix 1695 by not updating ancestors on zap (#1766) * fix 1695 by not updating ancestors on zap * update ancestors but only onPaid --- components/item-act.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/item-act.js b/components/item-act.js index 459fff7b..477cf459 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: { @@ -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 }) } })