diff --git a/frontend/src/routes/study/topics/[id]/questions/new/+page.svelte b/frontend/src/routes/study/topics/[id]/questions/new/+page.svelte index 9566df2..dec4c7b 100644 --- a/frontend/src/routes/study/topics/[id]/questions/new/+page.svelte +++ b/frontend/src/routes/study/topics/[id]/questions/new/+page.svelte @@ -158,21 +158,27 @@ return Array.from(set); }); - // 회차 변경 감지 → 문항 번호 자동 reset + // PR-7 fix: 회차 변경은 명시적 onchange 핸들러로 처리 (이전 $effect 패턴은 + // examRounds fetch 전에 첫 실행되며 f_qnum=1 로 reset 하는 race 발생). + // 사용자가 dropdown 으로 회차를 바꿀 때 + applyNewRound() 에서만 호출. let lastExamRound = $state(''); - $effect(() => { - if (f_exam_round && f_exam_round !== lastExamRound) { - // 기존 회차면 next_question_number, 아니면 1 - const found = examRounds.find((r) => r.exam_round === f_exam_round); - if (found && found.next_question_number) { - f_qnum = found.next_question_number; - } else if (!found) { - f_qnum = 1; - } + function onRoundChange() { + if (!f_exam_round) return; + if (f_exam_round === lastExamRound) return; + if (examRounds.length === 0) { + // examRounds 미적재 → onMount fallback 이 처리. 현재 호출은 skip. lastExamRound = f_exam_round; - refreshCompleteFlag(); + return; } - }); + const found = examRounds.find((r) => r.exam_round === f_exam_round); + if (found && found.next_question_number) { + f_qnum = found.next_question_number; + } else if (!found) { + f_qnum = 1; + } + lastExamRound = f_exam_round; + refreshCompleteFlag(); + } function refreshCompleteFlag() { const found = examRounds.find((r) => r.exam_round === f_exam_round); @@ -370,7 +376,7 @@ {#if f_exam_round_mode === 'select'}