Commit 60861e3
committed
fix: prevent overwriting unsaved user edits during async save in executeSave function
バグ: executeSave の await 中にユーザー入力 → save完了後 古い内容でstore上書き → CodeMirror/Monaco エディタ巻き戻り。さらに clearSaveTimer が新タイマー消去 → 新入力も永久に保存されない。
原因コード(修正前):
await fileRepository.saveFileByPath(projectId, path, content);
savingPaths.delete(path);
clearSaveTimer(path); // 新タイマー消す
updateAllTabsByPath(path, content, false); // 古いcontentでstore上書き
await 中に v2 入力 → store: v2、タイマー: 新 → save完了 → clearSaveTimer で新タイマー消去、updateAllTabsByPath で store を v1 に戻す → valtio検知 → React re-render → content prop変化 → CodeMirror view.dispatch 即座に全文置換、Monaco model.setValue で巻き戻り。
修正後:
await fileRepository.saveFileByPath(projectId, path, content);
savingPaths.delete(path);
const currentContent = getContentFromPanes(tabState.panes, path);
if (currentContent === undefined || currentContent === content) {
clearSaveTimer(path);
updateAllTabsByPath(path, content, false);
}
// 変わってたら何もしない → 新タイマー生存、store維持
save中に入力あり → 何もしない。新タイマーが生存し次のsaveで v2 保存。store上書きなし → re-renderなし → エディタ巻き戻りなし。1 parent be74314 commit 60861e3
1 file changed
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| |||
0 commit comments