fix: update url when moving away from history sidebar (#11618)

This commit is contained in:
Apoorv Mishra authored and GitHub committed 2026-03-02 17:51:43 -05:00
1 parent f0a7ee6df8
commit a4039ccc81
1 file changed
+20 -2
@@ -10,7 +10,12 @@ import PlaceholderText from "~/components/PlaceholderText";
import useMobile from "~/hooks/useMobile";
import useStores from "~/hooks/useStores";
import lazyWithRetry from "~/utils/lazyWithRetry";
import { matchDocumentHistory, matchDocumentSlug } from "~/utils/routeHelpers";
import history from "~/utils/history";
import {
documentPath,
matchDocumentHistory,
matchDocumentSlug,
} from "~/utils/routeHelpers";
import SidebarLayout from "~/scenes/Document/components/SidebarLayout";
const DocumentComments = lazyWithRetry(
@@ -70,7 +75,7 @@ const DocumentSidebarContent = observer(function DocumentSidebarContent({
* and clears it when closed or on unmount.
*/
export default function useDocumentSidebar() {
const { ui } = useStores();
const { ui, documents } = useStores();
const location = useLocation();
const setSidebar = useSetRightSidebar();
const isHistoryRoute = !!matchPath(location.pathname, {
@@ -87,6 +92,19 @@ export default function useDocumentSidebar() {
}
}, [isHistoryRoute, ui]);
// When the sidebar switches away from history while still on a /history URL,
// update the URL to remove the /history suffix.
React.useEffect(() => {
if (isHistoryRoute && ui.rightSidebar !== "history") {
const document = ui.activeDocumentId
? documents.get(ui.activeDocumentId)
: undefined;
if (document) {
history.push(documentPath(document));
}
}
}, [ui.rightSidebar, isHistoryRoute, ui.activeDocumentId, documents]);
React.useEffect(() => {
if (isOpen) {
setSidebar(