Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(payments): avoid reconciliation on passive status reads

Timothy Yine2d1adea615c
diff --git a/apps/cloud/app/composables/useCloudPayments.ts b/apps/cloud/app/composables/useCloudPayments.ts
index 7502e1b7..70e3bbd9 100644
--- a/apps/cloud/app/composables/useCloudPayments.ts
+++ b/apps/cloud/app/composables/useCloudPayments.ts
@@ -10,7 +10,7 @@ export function useCloudPayments(
let generation = 0,
alive = true,
pending = false
- async function refresh() {
+ async function refresh({ reconcile = true }: { reconcile?: boolean } = {}) {
const current = ++generation,
id = Number(toValue(workspaceId))
if (!id) {
@@ -28,6 +28,7 @@ export function useCloudPayments(
if (
alive &&
current === generation &&
+ reconcile &&
result.canManage &&
result.pending?.canRefresh
) {
@@ -72,16 +73,17 @@ export function useCloudPayments(
() => {
data.value = null
error.value = ''
- void refresh()
+ void refresh({ reconcile: true })
},
)
- onMounted(refresh)
+ onMounted(() => void refresh({ reconcile: true }))
onBeforeUnmount(() => {
alive = false
generation++
})
useIntervalFn(() => {
- if (document.visibilityState === 'visible' && !pending) void refresh()
+ if (document.visibilityState === 'visible' && !pending)
+ void refresh({ reconcile: false })
}, 15000)
return { data, busy, error, refresh }
}
diff --git a/apps/cloud/app/pages/account/plan.vue b/apps/cloud/app/pages/account/plan.vue
index b74a60da..57080941 100644
--- a/apps/cloud/app/pages/account/plan.vue
+++ b/apps/cloud/app/pages/account/plan.vue
@@ -11,7 +11,7 @@ const returned = useDodoCheckoutReturn(
() => selected.value,
() => !!payments.data.value?.enabled,
async () => {
- await Promise.all([refresh(), payments.refresh()])
+ await Promise.all([refresh(), payments.refresh({ reconcile: false })])
},
)
const latestSubscription = computed(() => {
diff --git a/tests/portal-review-regressions.test.ts b/tests/portal-review-regressions.test.ts
index b56b4597..e5b6fbb8 100644
--- a/tests/portal-review-regressions.test.ts
+++ b/tests/portal-review-regressions.test.ts
@@ -655,3 +655,47 @@ test('checkout verification diagnostics are re-read after 422 and non-owners do
}
}
})
+
+test('passive payment refreshes read state without duplicating provider confirmation', async () => {
+ let poll!: () => void
+ let mount!: () => void
+ const methods: string[] = []
+ const workspaceId = ref(1)
+ const module = load('apps/cloud/app/composables/useCloudPayments.ts', {
+ toValue,
+ document: { visibilityState: 'visible' },
+ $fetch: async (_path: string, options: any) => {
+ methods.push(options.method ?? 'GET')
+ return { canManage: true, pending: { id: 'checkout', canRefresh: 1 } }
+ },
+ onMounted: (callback: () => void) => {
+ mount = callback
+ },
+ onBeforeUnmount: () => {},
+ useIntervalFn: (callback: () => void) => {
+ poll = callback
+ },
+ })
+ const flush = async () => {
+ for (let n = 0; n < 12; n++) await nextTick()
+ }
+ const scope = effectScope()
+ try {
+ const payments = scope.run(() => module.useCloudPayments(workspaceId))!
+ mount()
+ await flush()
+ assert.deepEqual(methods.splice(0), ['GET', 'POST', 'GET'])
+ poll()
+ await flush()
+ assert.deepEqual(methods.splice(0), ['GET'])
+ await payments.refresh({ reconcile: false })
+ assert.deepEqual(methods.splice(0), ['GET'])
+ workspaceId.value = 2
+ await flush()
+ assert.deepEqual(methods.splice(0), ['GET', 'POST', 'GET'])
+ await payments.refresh()
+ assert.deepEqual(methods, ['GET', 'POST', 'GET'])
+ } finally {
+ scope.stop()
+ }
+})