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( () =>