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 3ab3876..9566df2 100644 --- a/frontend/src/routes/study/topics/[id]/questions/new/+page.svelte +++ b/frontend/src/routes/study/topics/[id]/questions/new/+page.svelte @@ -113,7 +113,8 @@ } // query string 처리 (회차 목록에서 ?exam_round=&start_qnum= 로 진입) - function applyQueryParams() { + // 반환: start_qnum 이 명시되었는지 여부 (true 면 onMount 가 next_question_number 자동 적용 skip) + function applyQueryParams(): boolean { const params = $page.url.searchParams; const r = params.get('exam_round'); const sq = params.get('start_qnum'); @@ -123,15 +124,30 @@ } if (sq) { const n = Number(sq); - if (Number.isFinite(n) && n > 0) f_qnum = n; + if (Number.isFinite(n) && n > 0) { + f_qnum = n; + return true; + } } + return false; } onMount(async () => { loadPersist(); - applyQueryParams(); + const explicitQnum = applyQueryParams(); await loadTopicAndRounds(); refreshCompleteFlag(); + // PR-7 fix: $effect 가 examRounds fetch 전에 첫 실행되면 found=undefined → f_qnum=1 로 + // 잘못 reset 됨. examRounds 채워진 후 명시적으로 next_question_number 재적용. + // start_qnum query 가 있으면 그 값 우선 (회차 목록의 [N번부터 이어서] 동선). + if (!explicitQnum && f_exam_round) { + const found = examRounds.find((r) => r.exam_round === f_exam_round); + if (found && found.next_question_number) { + f_qnum = found.next_question_number; + } + } + // $effect 의 lastExamRound 를 현재 값으로 sync — 첫 실행이 또 reset 하지 않도록. + lastExamRound = f_exam_round; }); // 드롭다운 옵션 합치기 (topic.exam_subjects + 기존 distinct, unique)