From 4b105586a98715d3ac147ab211363a97fc955edf Mon Sep 17 00:00:00 2001 From: MATHEUS LUIS LORSCHEITER Date: Tue, 3 Mar 2026 13:48:53 -0300 Subject: [PATCH] fix(client): ensure sidebar remains visible on shared subpages (#1887) * fix(client): ensure sidebar remains visible on shared subpages * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- apps/client/src/features/share/utils.ts | 17 +++++++++++++++++ apps/client/src/pages/share/shared-page.tsx | 16 ++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/client/src/features/share/utils.ts b/apps/client/src/features/share/utils.ts index cc73eb57..d5201693 100644 --- a/apps/client/src/features/share/utils.ts +++ b/apps/client/src/features/share/utils.ts @@ -66,3 +66,20 @@ export function buildSharedPageTree( return sortTree(tree); } + + +// Recursively checks if a page exists in the shared page tree. +export function isPageInTree( + tree: SharedPageTreeNode[], + pageSlugId: string, +): boolean { + for (const node of tree) { + if (node.slugId === pageSlugId) { + return true; + } + if (isPageInTree(node.children, pageSlugId)) { + return true; + } + } + return false; +} diff --git a/apps/client/src/pages/share/shared-page.tsx b/apps/client/src/pages/share/shared-page.tsx index 274b76cb..ff7302c5 100644 --- a/apps/client/src/pages/share/shared-page.tsx +++ b/apps/client/src/pages/share/shared-page.tsx @@ -8,6 +8,9 @@ import ReadonlyPageEditor from "@/features/editor/readonly-page-editor.tsx"; import { extractPageSlugId } from "@/lib"; import { Error404 } from "@/components/ui/error-404.tsx"; import ShareBranding from "@/features/share/components/share-branding.tsx"; +import { useAtomValue } from "jotai"; +import { sharedTreeDataAtom } from "@/features/share/atoms/shared-page-atom.ts"; +import { isPageInTree } from "@/features/share/utils.ts"; export default function SharedPage() { const { t } = useTranslation(); @@ -19,13 +22,22 @@ export default function SharedPage() { pageId: extractPageSlugId(pageSlug), }); + const sharedTreeData = useAtomValue(sharedTreeDataAtom); + useEffect(() => { if (shareId && data) { if (data.share.key !== shareId) { - navigate(`/share/${data.share.key}/p/${pageSlug}`, { replace: true }); + + // Check if the current page is part of the active sharing tree (sidebar) - If we are part of it, we will not redirect, keeping the sidebar visible. + const isPartOfTree = + sharedTreeData && isPageInTree(sharedTreeData, data.page.slugId); + + if (!isPartOfTree) { + navigate(`/share/${data.share.key}/p/${pageSlug}`, { replace: true }); + } } } - }, [shareId, data]); + }, [shareId, data, sharedTreeData]); if (isLoading) { return <>;