Skip to content

Commit a0af7bb

Browse files
committed
fix: guard against stale getTask() and getNotifyReady() calls
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 07ee9ae commit a0af7bb

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/assistant.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ export async function openAssistantForm({
290290

291291
if ([TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(task?.status)) {
292292
getTask(task.id).then(response => {
293+
if (task.id !== view.selectedTaskId) {
294+
console.debug('[assistant] ignoring stale getTask response for task', task.id, 'selected is', view.selectedTaskId)
295+
return
296+
}
293297
const updatedTask = response.data?.ocs?.data?.task
294298

295299
if (![TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(updatedTask?.status)) {
@@ -303,6 +307,9 @@ export async function openAssistantForm({
303307
}
304308

305309
getNotifyReady(task.id).then(response => {
310+
if (task.id !== view.selectedTaskId) {
311+
return
312+
}
306313
view.isNotifyEnabled = !!response.data?.ocs?.data?.id
307314
}).catch(error => {
308315
console.error('[assistant] get task notification status error', error)
@@ -922,6 +929,10 @@ export async function openAssistantTask(
922929

923930
if ([TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(task?.status)) {
924931
getTask(task.id).then(response => {
932+
if (task.id !== view.selectedTaskId) {
933+
console.debug('[assistant] ignoring stale getTask response for task', task.id, 'selected is', view.selectedTaskId)
934+
return
935+
}
925936
const updatedTask = response.data?.ocs?.data?.task
926937

927938
if (![TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(updatedTask?.status)) {
@@ -935,6 +946,9 @@ export async function openAssistantTask(
935946
}
936947

937948
getNotifyReady(task.id).then(response => {
949+
if (task.id !== view.selectedTaskId) {
950+
return
951+
}
938952
view.isNotifyEnabled = !!response.data?.ocs?.data?.id
939953
}).catch(error => {
940954
console.error('[assistant] get task notification status error', error)

src/views/AssistantPage.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ export default {
258258
259259
if ([TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(task?.status)) {
260260
getTask(task.id).then(response => {
261+
if (task.id !== this.task.id) {
262+
console.debug('[assistant] ignoring stale getTask response for task', task.id, 'selected is', this.task.id)
263+
return
264+
}
261265
const updatedTask = response.data?.ocs?.data?.task
262266
263267
if (![TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(updatedTask?.status)) {

0 commit comments

Comments
 (0)