Skip to content

Commit a3fb98e

Browse files
authored
Merge pull request #3226 from nextcloud/backport/3225/stable5.2
[stable5.2] fix: prevent race conditions while creating options
2 parents c3126c0 + 87d5c08 commit a3fb98e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/components/Questions/AnswerInput.vue

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,24 @@ export default {
278278
const answer = { ...this.answer }
279279
answer.text = value
280280
281-
// Dispatched for creation. Marked as synced
282-
this.$set(this.answer, 'local', false)
283-
const newAnswer = await this.createAnswer(answer)
281+
// Prevent any queued debounced PATCHes from running while creating
282+
this.queue.pause()
283+
try {
284+
// Dispatched for creation. Marked as synced
285+
this.$set(this.answer, 'local', false)
286+
const newAnswer = await this.createAnswer(answer)
284287
285-
// Forward changes, but use current answer.text to avoid erasing
286-
// any in-between changes while creating the answer
287-
newAnswer.text = this.$refs.input.value
288-
this.localText = ''
288+
// Forward changes, but use current answer.text to avoid erasing
289+
// any in-between changes while creating the answer
290+
newAnswer.text = this.$refs.input.value
291+
this.localText = ''
289292
290-
this.$emit('create-answer', this.index, newAnswer)
293+
this.$emit('create-answer', this.index, newAnswer)
294+
} finally {
295+
// Clear pending update tasks (stale PATCHes) before resuming processing
296+
this.queue.clear()
297+
this.queue.start()
298+
}
291299
},
292300
293301
/**

0 commit comments

Comments
 (0)