From 31d8d7252708e402bb88d4fb28dca2f1ed191f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Sat, 15 Aug 2026 20:16:17 +0000 Subject: [PATCH] closing a file no longer sends you home MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Open ~/Tests, double-click a file, edit it, save, close the pane — and the browser was back at ~. Reported from a real session, not found by reading. `onCloseViewer` was `setSearchParams({})`, which wipes the WHOLE query string. The folder lives in `?path=`, so closing the viewer deleted where you were along with what was on top of it. It also discarded anything `useGlobalQueryString` had put in the URL. The rule was already written down one file away, in `useFileBrowserApp.setViewerParams`: "`path` is not one of them — it is where you are, not what is on top of it — so it survives." Only the OPEN path honoured it. Close now deletes the ephemeral keys by name, which is exactly what `onCloseEphemeral`, `onCloseEphemeral2` and `onCloseChat` directly below it have always done — it was the single outlier among four handlers. Checked the other exits before calling it fixed: there is one `onClose` wired to the viewer, every other handler already used the targeted form, and the mount-cleanup effect deletes the same keys off `prev` rather than replacing the string. This was the only wholesale wipe in the repo. tsgo clean, frontend builds, 817 pass / 7 fail unchanged. Co-Authored-By: Claude Opus 5 --- .../useFileViewerPanels.tsx | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/workspaces/officerdev/src/hooks/useFileViewerPanels/useFileViewerPanels.tsx b/src/workspaces/officerdev/src/hooks/useFileViewerPanels/useFileViewerPanels.tsx index 883f1e57..0eddb4f0 100644 --- a/src/workspaces/officerdev/src/hooks/useFileViewerPanels/useFileViewerPanels.tsx +++ b/src/workspaces/officerdev/src/hooks/useFileViewerPanels/useFileViewerPanels.tsx @@ -51,7 +51,27 @@ export const useFileViewerPanels = (): EphemeralPanels | null => { ? viewerWithEphemeralLayout : singleViewerLayout; - const onCloseViewer = useCallback(() => setSearchParams({}), [setSearchParams]); + /** + * Close the viewer and everything stacked on it — and NOTHING else. + * + * This was `setSearchParams({})`, which wiped the whole query string. That took `path` with it, so + * closing a file you had opened inside a folder dropped you back at home: open ~/Tests, view a file, + * close it, and the browser is at ~. It also discarded whatever `useGlobalQueryString` had put there. + * + * The intent was already written down in `useFileBrowserApp.setViewerParams` — "`path` is not one of + * them, it is where you are, not what is on top of it, so it survives" — but only the OPEN path + * honoured it. Deleting the ephemeral keys by name is the same rule applied to close, and it is what + * `onCloseEphemeral` directly below has always done. + */ + const onCloseViewer = useCallback( + () => + setSearchParams((prev) => { + const next = new URLSearchParams(prev); + EPHEMERAL_KEYS.forEach((k) => next.delete(k)); + return next; + }), + [setSearchParams], + ); const onCloseEphemeral = useCallback( () =>