From b47c8a151e820608f1f93b300f8a3cc3eae857b0 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 17 Nov 2026 14:32:37 +0100 Subject: [PATCH] fix(editor): save the changes of a question one after another The editor sent each change of a question without waiting for the earlier request for the same question. When the server finished an earlier request last, for example for two changes of the extra settings, which are saved as a whole, the older value stayed in the database while the editor showed the newer one. A change of a field of a question is now saved once the earlier change of that field is saved, and of the changes made in the meantime only the latest is sent. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- src/composables/useQuestion.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/composables/useQuestion.ts b/src/composables/useQuestion.ts index e82281264..f96bffd6e 100644 --- a/src/composables/useQuestion.ts +++ b/src/composables/useQuestion.ts @@ -286,13 +286,39 @@ export function useQuestion(props: QuestionPropsLike, options: UseQuestionOption return shuffled } + const queuedValues = new Map() + const savingKeys = new Set() + + /** + * Persist a single question field to the backend once its earlier change is saved; of the values queued meanwhile only the latest is saved. + * + * @param key Question property name. + * @param value Question property value. + */ + async function saveQuestionProperty(key: string, value: unknown): Promise { + queuedValues.set(key, value) + if (savingKeys.has(key)) { + return + } + savingKeys.add(key) + try { + while (queuedValues.has(key)) { + const queuedValue = queuedValues.get(key) + queuedValues.delete(key) + await patchQuestionProperty(key, queuedValue) + } + } finally { + savingKeys.delete(key) + } + } + /** * Persist a single question field to the backend. * * @param key Question property name. * @param value Question property value. */ - async function saveQuestionProperty( + async function patchQuestionProperty( key: string, value: | string