From 269e384665fba8acc223a4b92c1e15722f2a58fa Mon Sep 17 00:00:00 2001 From: dwindown Date: Sun, 4 Jan 2026 20:10:11 +0700 Subject: [PATCH] Fix chapter pollution when switching between lessons in curriculum editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/components/admin/CurriculumEditor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/admin/CurriculumEditor.tsx b/src/components/admin/CurriculumEditor.tsx index cbcf585..a114242 100644 --- a/src/components/admin/CurriculumEditor.tsx +++ b/src/components/admin/CurriculumEditor.tsx @@ -212,7 +212,7 @@ export function CurriculumEditor({ productId }: CurriculumEditorProps) { mp4_url: lesson.mp4_url || '', video_host: lesson.video_host || 'youtube', 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); };