Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/pages/submit-assignment/AssignmentSubmitPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import AssignmentProblem from './ui/AssignmentProblem';
import ChatQuestionModal from '@/features/chat/ui/ChatQuestionModal';
import ChatIcon from '@/assets/svg/chatIcon.svg?react';
import {useState, useRef} from 'react';
import {useState, useRef, useEffect} from 'react';
import type {CodeEditorRef} from './ui/CodeEditor';
import SubmissionHistoryPanel from './ui/SubmissionHistoryPanel';

Expand All @@ -32,6 +32,10 @@
initialCodeId
);

useEffect(() => {
setCurrentCodeId(initialCodeId);
}, [assignmentId]);

Check warning on line 37 in src/pages/submit-assignment/AssignmentSubmitPage.tsx

View workflow job for this annotation

GitHub Actions / build-and-deploy

React Hook useEffect has a missing dependency: 'initialCodeId'. Either include it or remove the dependency array
Comment on lines +35 to +37

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

cat -n src/pages/submit-assignment/AssignmentSubmitPage.tsx | head -60

Repository: 2025-snowCode/snowCode-Client

Length of output: 2842


useEffect 의존성 누락으로 initialCodeId 변경이 반영되지 않을 수 있어요.

initialCodeIdlocation.state에서 추출되어 렌더링마다 새로 평가되는데, effect 내부에서 사용 중인 initialCodeId가 의존성 배열에 없습니다. 같은 assignmentId에서 다른 codeId를 가진 state로 이동할 때 currentCodeId가 동기화되지 않을 수 있습니다.

✅ 제안 수정
  useEffect(() => {
    setCurrentCodeId(initialCodeId);
- }, [assignmentId]);
+ }, [assignmentId, initialCodeId]);

React 공식 문서의 useEffect 의존성 배열 가이드에서 "effect가 사용하는 모든 반응형 값(props, state, 파생 값)을 의존성에 포함"해야 한다는 규칙을 참고해 주세요.

🧰 Tools
🪛 GitHub Check: build-and-deploy

[warning] 37-37:
React Hook useEffect has a missing dependency: 'initialCodeId'. Either include it or remove the dependency array

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/submit-assignment/AssignmentSubmitPage.tsx` around lines 35 - 37,
The effect in AssignmentSubmitPage (useEffect that calls
setCurrentCodeId(initialCodeId)) is missing initialCodeId in its dependency
array so changes to initialCodeId (from location.state) won't update
currentCodeId; update the dependency array to include initialCodeId (in addition
to assignmentId) so the effect re-runs when either assignmentId or initialCodeId
changes, ensuring setCurrentCodeId(initialCodeId) stays synchronized with the
incoming state.


const [{data: assignment}, {data: courseDetails}] = useSuspenseQueries({
queries: [
assignmentQueries.getAssignment(Number(assignmentId)),
Expand Down
Loading