Fix chapter pollution when switching between lessons in curriculum editor

The issue was that handleEditLesson was setting lessonForm.chapters to a direct
reference of lesson.chapters instead of creating a copy. This caused mutations
to the form to also modify the lesson objects in the lessons array state.

When editing lesson 3 with chapters, then switching to edit lesson 2 (which had
no chapters), the form would still show lesson 3's chapters because it was
referencing the same array object.

Fix: Use spread operator [...lesson.chapters] to create a shallow copy of the
chapters array, preventing shared references between form state and lessons state.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-01-04 20:10:11 +07:00
parent d6126d1943
commit 269e384665

View File

@@ -212,7 +212,7 @@ export function CurriculumEditor({ productId }: CurriculumEditorProps) {
mp4_url: lesson.mp4_url || '', mp4_url: lesson.mp4_url || '',
video_host: lesson.video_host || 'youtube', video_host: lesson.video_host || 'youtube',
release_at: lesson.release_at ? lesson.release_at.split('T')[0] : '', release_at: lesson.release_at ? lesson.release_at.split('T')[0] : '',
chapters: lesson.chapters || [], chapters: lesson.chapters ? [...lesson.chapters] : [], // Create a copy to avoid mutation
}); });
setLessonDialogOpen(true); setLessonDialogOpen(true);
}; };