mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
* fix(editor): address Codex review feedback on PR #808 Three issues raised on the merged editor-tab-form PR: P1 — Host-picker switch ignored onDisconnect cancellation SftpPaneDialogs' onSelectLocal / onSelectHost awaited onDisconnect() and unconditionally called onConnect() regardless of the dirty-editor prompt outcome. A user who hit Cancel on the "unsaved changes" dialog would still end up switched to the new host, stranding the editor tabs on a now-stale connection. Change onDisconnect to return Promise<boolean> (true when the disconnect actually ran, false on prompt cancel) and gate onConnect on it. Propagate the new signature through SftpPaneCallbacks, the pane-actions hook result, and both left/right implementations. P2 — setIsQuitting leaked across canceled quits electron/main.cjs called windowManager.setIsQuitting(true) at the top of before-quit, before the dirty-editor check returned. If the renderer reported hasDirty=true and the quit was canceled, isQuitting stayed true, changing later window-close behavior (close-to-tray paths gated on !isQuitting would stop firing). Move the setIsQuitting call into a commitQuit() helper that only runs once we've decided to actually proceed — on hasDirty=true we leave state untouched. P2 — SftpSidePanel unmount only cleaned active-pane connections The cleanup effect inspected only leftPane / rightPane (the active tab per side), missing editor tabs tied to inactive tabs in the same side panel. On unmount those tabs would survive with a dead save bridge. Iterate leftTabs.tabs and rightTabs.tabs and collect every connection id before calling forceCloseBySessions. npm test — 212/212 pass, tsc error count unchanged from main, lint clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * perf(editor): stabilize bridge registration effect and memoize filename dedup Two perf concerns from a focused leak/perf audit of PR #808: 1. Bridge writer effect re-ran on every SFTP state change. SftpView / SftpSidePanel registered their bridge writer in an effect with `[sftp]` deps. The `sftp` object identity changes on every SFTP state update — transfer progress, directory listing, pane updates, tab switches — so the effect would unregister+reregister constantly during routine SFTP use. Not a leak (React runs cleanup before each re-effect), just high-frequency churn on the hot path. Route through sftpRef and run the effect once; writeTextFileByConnection is a methodsRef-backed dispatcher that stays valid across sftp re-renders. 2. O(n²) filename disambiguation scan in TopTabs render. Each editor tab ran `editorTabs.filter(same fileName)` inside the per-tab render branch. Negligible at ~20 tabs but trivially fixable: build a fileName→count map in a useMemo keyed on editorTabs and look up in O(1). Separately noted but NOT fixed here (needs a store refactor and deserves its own PR): App.tsx subscribing to useEditorTabs() means every keystroke in an editor tab re-renders the App root. Would need a useEditorTabIds() selector that only notifies on add/remove. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>