From 5b7e06abc1819e7afdcc370326050c2af91ecd94 Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Tue, 28 Apr 2026 13:08:05 +0900 Subject: [PATCH] =?UTF-8?q?fix(study):=20=EC=9E=85=EB=A0=A5=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A7=84=EC=9E=85=20=EC=8B=9C=20=ED=9A=8C?= =?UTF-8?q?=EC=B0=A8=20next=5Fquestion=5Fnumber=20race=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $effect 가 examRounds fetch 전에 첫 실행되면 found=undefined → f_qnum=1 로 강제 reset. 그 후 examRounds fetch 완료해도 effect 재실행 안 돼서 사용자가 그대로 입력 시작 → 회차 안 문항 번호 중복 (1,2,3,1,1,...) 발생. 수정: - applyQueryParams() 가 start_qnum 명시 여부 boolean 반환 - onMount 에서 await loadTopicAndRounds() 후 explicit start_qnum 없고 f_exam_round 가 있으면 examRounds.find().next_question_number 명시 적용 - lastExamRound 를 현재 값으로 sync — $effect 첫 실행이 또 reset 안 함 이미 발생한 데이터(중복 qnum) 는 사용자 직접 정정 또는 별도 SQL 보정 필요. 이 fix 후 새로고침/재진입 시에는 정상 next 적용. --- .../topics/[id]/questions/new/+page.svelte | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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)