From 9b9ec2cd95bc1115130d9dc204f027d1dc71f81b Mon Sep 17 00:00:00 2001 From: YuanShiJiLoong <2450829984@qq.com> Date: Tue, 24 Feb 2026 21:18:06 +0900 Subject: [PATCH] fix: deleteChapter is async, must await to prevent data loss --- app/components/Sidebar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/components/Sidebar.js b/app/components/Sidebar.js index 5ffdaf3..b16ca84 100644 --- a/app/components/Sidebar.js +++ b/app/components/Sidebar.js @@ -57,13 +57,13 @@ export default function Sidebar() { }, [getNextChapterTitle, showToast, addChapter, setActiveChapterId, t]); // 删除章节 - const handleDeleteChapter = useCallback((id) => { - if (chapters.length <= 1) { + const handleDeleteChapter = useCallback(async (id) => { + if (!Array.isArray(chapters) || chapters.length <= 1) { showToast(t('sidebar.alertRetainOne'), 'error'); return; } const ch = chapters.find(c => c.id === id); - const remaining = deleteChapter(id); + const remaining = await deleteChapter(id); setChapters(remaining); if (activeChapterId === id) { setActiveChapterId(remaining[0]?.id || null);