From 283453682c7cde56283edf462d1dffb60c0bfbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Fri, 18 Sep 2026 11:45:26 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=E2=86=A9=EF=B8=8F=20the=20shell=20back?= =?UTF-8?q?=20button=20never=20leaves=20the=20app=20-=20with=20an=20in-app?= =?UTF-8?q?=20history=20entry=20it=20still=20goes=20back=20(useCanGoBack?= =?UTF-8?q?=20+=20=20=20router.history.back)=20-=20on=20a=20deep=20link,?= =?UTF-8?q?=20new=20tab=20or=20reload=20it=20navigates=20to=20the=20neares?= =?UTF-8?q?t=20existing=20=20=20parent=20route=20instead=20of=20calling=20?= =?UTF-8?q?window.history.back()=20-=20instances=20go=20to=20the=20/course?= =?UTF-8?q?s=20hub,=20exam=20rooms=20to=20/exams,=20profiles=20home=20-=20?= =?UTF-8?q?backTarget=20is=20a=20pure=20helper=20over=20the=20router's=20r?= =?UTF-8?q?oute=20paths,=20with=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layout/app-shell.tsx | 13 +++++++++-- src/lib/back-target.test.ts | 35 +++++++++++++++++++++++++++++ src/lib/back-target.ts | 33 +++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/lib/back-target.test.ts create mode 100644 src/lib/back-target.ts diff --git a/src/components/layout/app-shell.tsx b/src/components/layout/app-shell.tsx index 5c56b72..95ec3cc 100644 --- a/src/components/layout/app-shell.tsx +++ b/src/components/layout/app-shell.tsx @@ -1,5 +1,5 @@ import { Show, createEffect, createMemo, createSignal, type ParentProps } from "solid-js"; -import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; +import { Link, useCanGoBack, useLocation, useNavigate, useRouter } from "@tanstack/solid-router"; import { LogoMark } from "@/components/brand/logo-mark"; import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; import { CelebiPanel } from "@/components/layout/celebi-panel"; @@ -21,6 +21,7 @@ import { celebiPanelOpen, openCelebiPanel, setCelebiPanelOpen } from "@/stores/c import { commandPaletteOpen, openCommandPalette, setCommandPaletteOpen } from "@/stores/command-palette"; import { ShellFeedProvider } from "@/stores/shell-feed-context"; import { usePreferences, useT } from "@/stores/preferences-context"; +import { backTarget } from "@/lib/back-target"; import { cn } from "@/lib/cn"; import { ModuleGate } from "@/components/layout/module-gate"; @@ -37,6 +38,14 @@ export function AppShell(props: ParentProps) { const [profileOpen, setProfileOpen] = createSignal(false); const collapsed = () => prefs.sidebarCollapsed(); const location = useLocation(); + const router = useRouter(); + const canGoBack = useCanGoBack(); + // A deep link or a fresh tab has no in-app entry behind it, and + // history.back() there would leave the app: go to the parent route instead. + const goBack = () => { + if (canGoBack()) return router.history.back(); + void navigate({ to: backTarget(location().pathname, Object.keys(router.routesByPath)) }); + }; const fullScreen = () => location().pathname.startsWith("/exam-room/"); const routeLabel = createMemo(() => { const key = routeLabelKey(location().pathname, auth.user()?.role); @@ -130,7 +139,7 @@ export function AppShell(props: ParentProps) {