File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -278,16 +278,27 @@ 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)
284-
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 = ' '
289-
290- this .$emit (' create-answer' , this .index , newAnswer)
281+ // Prevent any queued debounced PATCHes from running while creating
282+ this .queue .pause ()
283+ try {
284+ const newAnswer = await this .createAnswer (answer)
285+ if (! newAnswer || ! newAnswer .id ) {
286+ // Creation failed or response invalid — keep the local input as-is
287+ return
288+ }
289+
290+ // Forward changes, but use current input value to avoid erasing
291+ // any in-between changes while creating the answer
292+ const currentText = this .$refs .input ? .value ?? ' '
293+ newAnswer .text = currentText
294+ this .localText = ' '
295+
296+ this .$emit (' create-answer' , this .index , newAnswer)
297+ } finally {
298+ // Clear pending update tasks (stale PATCHes) before resuming processing
299+ this .queue .clear ()
300+ this .queue .start ()
301+ }
291302 },
292303
293304 /**
You can’t perform that action at this time.
0 commit comments