Skip to content

Commit 90ef888

Browse files
Fix Cmd+N creating duplicate notes in dev mode
The Tauri event listeners were registered via async Promise.all, but cleanup ran before promises resolved (unlisten vars still null). In React StrictMode this left two active listeners per event, causing double note creation. Use a cancelled flag so late-resolving disposers clean up immediately. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2fb4c97 commit 90ef888

1 file changed

Lines changed: 11 additions & 25 deletions

File tree

app/src/app.tsx

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -215,40 +215,26 @@ function App() {
215215
});
216216

217217
useEffect(() => {
218-
let unlistenCommandPalette: (() => void) | null = null;
219-
let unlistenEditorFind: (() => void) | null = null;
220-
let unlistenNewNote: (() => void) | null = null;
221-
let unlistenNotesSearch: (() => void) | null = null;
222-
let unlistenSettings: (() => void) | null = null;
218+
let cancelled = false;
219+
const disposers: (() => void)[] = [];
223220

224221
void Promise.all([
225222
listen(TAURI_EVENT_COMMAND_PALETTE, handleCommandPaletteMenuEvent),
226223
listen(TAURI_EVENT_EDITOR_FIND, handleEditorFindMenuEvent),
227224
listen(TAURI_EVENT_NEW_NOTE, handleNewNoteMenuEvent),
228225
listen(TAURI_EVENT_NOTES_SEARCH, handleNotesSearchMenuEvent),
229226
listen(TAURI_EVENT_SETTINGS, handleSettingsMenuEvent),
230-
]).then(
231-
([
232-
disposeCommandPalette,
233-
disposeEditorFind,
234-
disposeNewNote,
235-
disposeNotesSearch,
236-
disposeSettings,
237-
]) => {
238-
unlistenCommandPalette = disposeCommandPalette;
239-
unlistenEditorFind = disposeEditorFind;
240-
unlistenNewNote = disposeNewNote;
241-
unlistenNotesSearch = disposeNotesSearch;
242-
unlistenSettings = disposeSettings;
243-
},
244-
);
227+
]).then((unlistenFns) => {
228+
if (cancelled) {
229+
for (const fn of unlistenFns) fn();
230+
} else {
231+
disposers.push(...unlistenFns);
232+
}
233+
});
245234

246235
return () => {
247-
unlistenCommandPalette?.();
248-
unlistenEditorFind?.();
249-
unlistenNewNote?.();
250-
unlistenNotesSearch?.();
251-
unlistenSettings?.();
236+
cancelled = true;
237+
for (const fn of disposers) fn();
252238
};
253239
}, []);
254240

0 commit comments

Comments
 (0)