Skip to content

The only tool you need to know what is happening and how to fix it.

back button fixed - we're now going back without using params and doing proper back with a fallback option available in case they navigate to the url itself

ddux63a91ed9025a
diff --git a/frontend/src/lib/state/auth.svelte.ts b/frontend/src/lib/state/auth.svelte.ts
index c717c656..805c27c5 100644
--- a/frontend/src/lib/state/auth.svelte.ts
+++ b/frontend/src/lib/state/auth.svelte.ts
@@ -1,3 +1,5 @@
+import { clearNavDepth } from '$lib/utils/back-navigation';
+
class AuthState {
token = $state<string | null>(localStorage.getItem('APP_TOKEN'));
@@ -21,6 +23,7 @@ class AuthState {
logout() {
this.token = null;
+ clearNavDepth();
}
}
diff --git a/frontend/src/lib/utils/back-navigation.ts b/frontend/src/lib/utils/back-navigation.ts
new file mode 100644
index 00000000..c107972b
--- /dev/null
+++ b/frontend/src/lib/utils/back-navigation.ts
@@ -0,0 +1,84 @@
+import { goto } from '$app/navigation';
+
+const NAV_DEPTH_KEY = 'traceway_nav_depth';
+
+export interface SmartBackOptions {
+ fallbackPath: string;
+}
+
+/**
+ * Get current navigation depth
+ */
+function getNavDepth(): number {
+ try {
+ return parseInt(sessionStorage.getItem(NAV_DEPTH_KEY) || '0', 10);
+ } catch {
+ return 0;
+ }
+}
+
+/**
+ * Set navigation depth
+ */
+function setNavDepth(depth: number): void {
+ try {
+ sessionStorage.setItem(NAV_DEPTH_KEY, String(depth));
+ } catch {
+ // Ignore storage errors
+ }
+}
+
+/**
+ * Called when navigating to a new page (pathname changed)
+ */
+export function incrementNavDepth(): void {
+ setNavDepth(getNavDepth() + 1);
+}
+
+/**
+ * Called on popstate (browser back/forward)
+ */
+export function decrementNavDepth(): void {
+ setNavDepth(Math.max(0, getNavDepth() - 1));
+}
+
+/**
+ * Clear navigation depth (call on logout)
+ */
+export function clearNavDepth(): void {
+ try {
+ sessionStorage.removeItem(NAV_DEPTH_KEY);
+ } catch {
+ // Ignore storage errors
+ }
+}
+
+/**
+ * Check if there's internal history to go back to
+ */
+export function hasInternalHistory(): boolean {
+ return getNavDepth() > 0;
+}
+
+/**
+ * Create a smart back button handler that:
+ * 1. Uses history.back() if there's valid internal navigation history
+ * 2. Falls back to the specified path if no history (direct URL access, refresh with no prior nav)
+ */
+export function createSmartBackHandler(options: SmartBackOptions): (e: MouseEvent) => void {
+ const { fallbackPath } = options;
+
+ return (event: MouseEvent) => {
+ // Ctrl/Cmd+Click: open fallback in new tab
+ if (event.ctrlKey || event.metaKey) {
+ window.open(fallbackPath, '_blank');
+ return;
+ }
+
+ if (hasInternalHistory()) {
+ history.back();
+ } else {
+ goto(fallbackPath);
+ }
+ };
+}
diff --git a/frontend/src/lib/utils/url-params.ts b/frontend/src/lib/utils/url-params.ts
index 3a9dcdab..ca8b94af 100644
--- a/frontend/src/lib/utils/url-params.ts
+++ b/frontend/src/lib/utils/url-params.ts
@@ -83,7 +83,8 @@ export function updateUrl(
): void {
if (!browser) return;
- const { pushToHistory = true } = options;
+ // Note: pushToHistory option is kept for API compatibility but we always use replaceState
+ // This ensures back button navigates to previous PAGE, not previous params on same page
const urlParams = new URLSearchParams();
for (const [key, value] of Object.entries(params)) {
@@ -96,7 +97,7 @@ export function updateUrl(
// eslint-disable-next-line svelte/no-navigation-without-resolve
goto(newUrl, {
- replaceState: !pushToHistory,
+ replaceState: true,
noScroll: true,
keepFocus: true
});
diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte
index d8019918..42e6386f 100644
--- a/frontend/src/routes/+layout.svelte
+++ b/frontend/src/routes/+layout.svelte
@@ -1,10 +1,11 @@
<script lang="ts">
import './layout.css';
- import { goto } from '$app/navigation';
+ import { goto, afterNavigate } from '$app/navigation';
import { authState } from '$lib/state/auth.svelte';
import { projectsState } from '$lib/state/projects.svelte';
import { themeState, initTheme, toggleTheme } from '$lib/state/theme.svelte';
import { initTimezone } from '$lib/state/timezone.svelte';
+ import { incrementNavDepth, decrementNavDepth } from '$lib/utils/back-navigation';
import AppSidebar from '$lib/components/app-sidebar.svelte';
import AddProjectModal from '$lib/components/add-project-modal.svelte';
import FrameworkIcon from '$lib/components/framework-icon.svelte';
@@ -19,6 +20,24 @@
let { children } = $props();
let showAddProjectModal = $state(false);
+ // Track navigation depth for smart back buttons
+ let lastPathname = '';
+ afterNavigate((navigation) => {
+ if (!navigation.to?.url) return;
+ const newPathname = navigation.to.url.pathname;
+
+ if (navigation.type === 'popstate') {
+ // Browser back/forward button
+ decrementNavDepth();
+ } else if (newPathname !== lastPathname) {
+ // Navigated to a different page (not just param change)
+ incrementNavDepth();
+ }
+ // Param-only changes (same pathname) don't affect depth
+
+ lastPathname = newPathname;
+ });
+
onMount(() => {
initTheme();
initTimezone();
diff --git a/frontend/src/routes/endpoints/[endpoint]/+page.svelte b/frontend/src/routes/endpoints/[endpoint]/+page.svelte
index 6635b08a..ddbf9b39 100644
--- a/frontend/src/routes/endpoints/[endpoint]/+page.svelte
+++ b/frontend/src/routes/endpoints/[endpoint]/+page.svelte
@@ -15,6 +15,7 @@
import { projectsState } from '$lib/state/projects.svelte';
import ScopeDisplay from '$lib/components/scope-display.svelte';
import { createRowClickHandler } from '$lib/utils/navigation';
+ import { createSmartBackHandler } from '$lib/utils/back-navigation';
import PaginationFooter from '$lib/components/ui/pagination-footer/pagination-footer.svelte';
import PageHeader from '$lib/components/issues/page-header.svelte';
import { resolve } from '$app/paths';
@@ -226,7 +227,7 @@
status={404}
title="Endpoint Not Found"
description="The endpoint you're looking for doesn't exist or has no recorded transactions."
- onBack={createRowClickHandler(resolve('/endpoints'), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/endpoints') })}
backLabel="Back to Transactions"
onRetry={() => loadData(false)}
identifier={decodeURIComponent(data.endpoint)}
@@ -236,7 +237,7 @@
status={errorStatus === 400 ? 400 : errorStatus === 422 ? 422 : 400}
title="Failed to Load Transactions"
description={error}
- onBack={createRowClickHandler(resolve('/endpoints'), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/endpoints') })}
backLabel="Back to Transactions"
onRetry={() => loadData(false)}
/>
@@ -247,7 +248,7 @@
<PageHeader
title={decodeURIComponent(data.endpoint)}
subtitle="Transaction instances for this endpoint"
- onBack={createRowClickHandler(resolve("/endpoints"), "presets", "from", "to")}
+ onBack={createSmartBackHandler({ fallbackPath: resolve("/endpoints") })}
/>
<div class="flex flex-col">
diff --git a/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.svelte b/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.svelte
index 575482ce..6936a95a 100644
--- a/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.svelte
+++ b/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.svelte
@@ -17,7 +17,7 @@
import SegmentEmptyState from '$lib/components/segments/segment-empty-state.svelte';
import type { TransactionDetailResponse } from '$lib/types/segments';
import PageHeader from '$lib/components/issues/page-header.svelte';
- import { createRowClickHandler } from '$lib/utils/navigation';
+ import { createSmartBackHandler } from '$lib/utils/back-navigation';
import { resolve } from '$app/paths';
let { data } = $props();
@@ -72,7 +72,7 @@
<div class="space-y-6">
<PageHeader
title={decodeURIComponent(data.endpoint)} subtitle={`Endpoint ID: ${data.endpointId}`}
- onBack={createRowClickHandler(resolve('/endpoints/[endpoint]', {endpoint: encodeURIComponent(data.endpoint)}))} />
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/endpoints/[endpoint]', {endpoint: encodeURIComponent(data.endpoint)}) })} />
{#if loading}
@@ -84,7 +84,7 @@
status={404}
title="Endpoint Not Found"
description="The endpoint instance you're looking for doesn't exist or may have expired."
- onBack={createRowClickHandler(resolve('/endpoints/[endpoint]', {endpoint: encodeURIComponent(data.endpoint)}))}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/endpoints/[endpoint]', {endpoint: encodeURIComponent(data.endpoint)}) })}
backLabel="Back to Endpoint"
onRetry={loadData}
identifier={data.endpointId}
@@ -94,7 +94,7 @@
status={400}
title="Failed to Load Endpoint"
description={error}
- onBack={createRowClickHandler(resolve('/endpoints/[endpoint]', {endpoint: encodeURIComponent(data.endpoint)}))}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/endpoints/[endpoint]', {endpoint: encodeURIComponent(data.endpoint)}) })}
backLabel="Back to Endpoint"
onRetry={loadData}
/>
diff --git a/frontend/src/routes/issues/[exceptionHash]/+page.svelte b/frontend/src/routes/issues/[exceptionHash]/+page.svelte
index 5fd1b45c..f5a0c1df 100644
--- a/frontend/src/routes/issues/[exceptionHash]/+page.svelte
+++ b/frontend/src/routes/issues/[exceptionHash]/+page.svelte
@@ -12,7 +12,7 @@
import ArchiveConfirmationDialog from '$lib/components/archive-confirmation-dialog.svelte';
import Archive from '@lucide/svelte/icons/archive';
import type { ExceptionGroup, ExceptionOccurrence, LinkedTransaction } from '$lib/types/exceptions';
- import { createRowClickHandler } from '$lib/utils/navigation';
+ import { createSmartBackHandler } from '$lib/utils/back-navigation';
import { resolve } from '$app/paths';
let group = $state<ExceptionGroup | null>(null);
@@ -116,7 +116,7 @@
<PageHeader
title={firstLineOfStackTrace}
subtitle="Exception Hash: {exceptionHash}"
- onBack={createRowClickHandler(resolve("/issues"))}
+ onBack={createSmartBackHandler({ fallbackPath: resolve("/issues") })}
/>
</div>
@@ -129,7 +129,7 @@
status={404}
title="Exception Not Found"
description="The exception you're looking for doesn't exist or may have been removed. It's possible the data has expired or the link is incorrect."
- onBack={createRowClickHandler(resolve('/issues'), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/issues') })}
backLabel="Back to Issues"
onRetry={() => loadData()}
identifier={exceptionHash}
@@ -139,7 +139,7 @@
status={400}
title="Something Went Wrong"
description={error}
- onBack={createRowClickHandler(resolve('/issues'), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/issues') })}
backLabel="Back to Issues"
onRetry={() => loadData()}
/>
diff --git a/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.svelte b/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.svelte
index be105cfe..9c6dbe07 100644
--- a/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.svelte
+++ b/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.svelte
@@ -8,7 +8,7 @@
import { formatDateTime } from '$lib/utils/formatters';
import { StackTraceCard, EventCard, EventsTable, PageHeader } from '$lib/components/issues';
import type { ExceptionGroup, ExceptionOccurrence, LinkedTransaction } from '$lib/types/exceptions';
- import { createRowClickHandler } from '$lib/utils/navigation';
+ import { createSmartBackHandler } from '$lib/utils/back-navigation';
import { resolve } from '$app/paths';
import ArchiveConfirmationDialog from '$lib/components/archive-confirmation-dialog.svelte';
import { goto } from '$app/navigation';
@@ -136,7 +136,7 @@
<PageHeader
title={firstLineOfStackTrace}
subtitle={subtitleText}
- onBack={createRowClickHandler(resolve("/issues/[exceptionHash]", {exceptionHash: data.exceptionHash}))}
+ onBack={createSmartBackHandler({ fallbackPath: resolve("/issues/[exceptionHash]", {exceptionHash: data.exceptionHash}) })}
/>
{#if loading && !group}
@@ -148,7 +148,7 @@
status={404}
title="Event Not Found"
description="The specific event you're looking for doesn't exist or may have been removed."
- onBack={createRowClickHandler(resolve('/issues/[exceptionHash]', {exceptionHash: data.exceptionHash}), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/issues/[exceptionHash]', {exceptionHash: data.exceptionHash}) })}
backLabel="Back to Exception"
onRetry={() => loadData()}
/>
@@ -157,7 +157,7 @@
status={400}
title="Something Went Wrong"
description={error}
- onBack={createRowClickHandler(resolve('/issues/[exceptionHash]', {exceptionHash: data.exceptionHash}), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/issues/[exceptionHash]', {exceptionHash: data.exceptionHash}) })}
backLabel="Back to Exception"
onRetry={() => loadData()}
/>
diff --git a/frontend/src/routes/issues/[exceptionHash]/events/+page.svelte b/frontend/src/routes/issues/[exceptionHash]/events/+page.svelte
index 566ea93e..cba8f729 100644
--- a/frontend/src/routes/issues/[exceptionHash]/events/+page.svelte
+++ b/frontend/src/routes/issues/[exceptionHash]/events/+page.svelte
@@ -3,6 +3,7 @@
import { page } from '$app/state';
import { goto } from '$app/navigation';
import { createRowClickHandler } from '$lib/utils/navigation';
+ import { createSmartBackHandler } from '$lib/utils/back-navigation';
import { truncateStackTrace, formatDateTime } from '$lib/utils/formatters';
import { getTimezone } from '$lib/state/timezone.svelte';
import { api } from '$lib/api';
@@ -135,7 +136,7 @@
<div class="space-y-6">
<!-- Header -->
<div class="flex items-center justify-between">
- <Button variant="outline" size="sm" onclick={() => goto(`/issues/${page.params.exceptionHash}`)}>
+ <Button variant="outline" size="sm" onclick={createSmartBackHandler({ fallbackPath: resolve('/issues/[exceptionHash]', {exceptionHash: page.params.exceptionHash ?? ''}) })}>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2">
<path d="m12 19-7-7 7-7"/><path d="M19 12H5"/>
</svg>
@@ -164,7 +165,7 @@
status={404}
title="Exception Not Found"
description="The exception you're looking for doesn't exist or may have been removed."
- onBack={createRowClickHandler(resolve('/issues'), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/issues') })}
backLabel="Back to Issues"
onRetry={() => loadData()}
identifier={page.params.exceptionHash}
@@ -174,7 +175,7 @@
status={400}
title="Something Went Wrong"
description={error}
- onBack={createRowClickHandler(resolve('/issues'), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/issues') })}
backLabel="Back to Issues"
onRetry={() => loadData()}
/>
diff --git a/frontend/src/routes/tasks/[task]/+page.svelte b/frontend/src/routes/tasks/[task]/+page.svelte
index ada4acd5..7ef53252 100644
--- a/frontend/src/routes/tasks/[task]/+page.svelte
+++ b/frontend/src/routes/tasks/[task]/+page.svelte
@@ -13,6 +13,7 @@
import { projectsState } from '$lib/state/projects.svelte';
import ScopeDisplay from '$lib/components/scope-display.svelte';
import { createRowClickHandler } from '$lib/utils/navigation';
+ import { createSmartBackHandler } from '$lib/utils/back-navigation';
import PaginationFooter from '$lib/components/ui/pagination-footer/pagination-footer.svelte';
import PageHeader from '$lib/components/issues/page-header.svelte';
import { resolve } from '$app/paths';
@@ -210,7 +211,7 @@
status={404}
title="Task Not Found"
description="The task you're looking for doesn't exist or has no recorded executions."
- onBack={createRowClickHandler(resolve('/tasks'), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/tasks') })}
backLabel="Back to Tasks"
onRetry={() => loadData(false)}
identifier={decodeURIComponent(data.task)}
@@ -220,7 +221,7 @@
status={errorStatus === 400 ? 400 : errorStatus === 422 ? 422 : 400}
title="Failed to Load Tasks"
description={error}
- onBack={createRowClickHandler(resolve('/tasks'), 'presets', 'from', 'to')}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/tasks') })}
backLabel="Back to Tasks"
onRetry={() => loadData(false)}
/>
@@ -231,7 +232,7 @@
<PageHeader
title={decodeURIComponent(data.task)}
subtitle="Task instances"
- onBack={createRowClickHandler(resolve("/tasks"), "presets", "from", "to")}
+ onBack={createSmartBackHandler({ fallbackPath: resolve("/tasks") })}
/>
<div class="flex flex-col">
diff --git a/frontend/src/routes/tasks/[task]/[taskId]/+page.svelte b/frontend/src/routes/tasks/[task]/[taskId]/+page.svelte
index 61bb5c19..efb41ddc 100644
--- a/frontend/src/routes/tasks/[task]/[taskId]/+page.svelte
+++ b/frontend/src/routes/tasks/[task]/[taskId]/+page.svelte
@@ -16,7 +16,7 @@
import SegmentWaterfall from '$lib/components/segments/segment-waterfall.svelte';
import SegmentEmptyState from '$lib/components/segments/segment-empty-state.svelte';
import PageHeader from '$lib/components/issues/page-header.svelte';
- import { createRowClickHandler } from '$lib/utils/navigation';
+ import { createSmartBackHandler } from '$lib/utils/back-navigation';
import { resolve } from '$app/paths';
type TaskDetailResponse = {
@@ -87,7 +87,7 @@
<div class="space-y-6">
<PageHeader
title={decodeURIComponent(data.task)} subtitle={`Task ID: ${data.taskId}`}
- onBack={createRowClickHandler(resolve('/tasks/[task]', {task: encodeURIComponent(data.task)}))} />
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/tasks/[task]', {task: encodeURIComponent(data.task)}) })} />
{#if loading}
@@ -99,7 +99,7 @@
status={404}
title="Task Not Found"
description="The task instance you're looking for doesn't exist or may have expired."
- onBack={createRowClickHandler(resolve('/tasks/[task]', {task: encodeURIComponent(data.task)}))}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/tasks/[task]', {task: encodeURIComponent(data.task)}) })}
backLabel="Back to Task"
onRetry={loadData}
identifier={data.taskId}
@@ -109,7 +109,7 @@
status={400}
title="Failed to Load Task"
description={error}
- onBack={createRowClickHandler(resolve('/tasks/[task]', {task: encodeURIComponent(data.task)}))}
+ onBack={createSmartBackHandler({ fallbackPath: resolve('/tasks/[task]', {task: encodeURIComponent(data.task)}) })}
backLabel="Back to Task"
onRetry={loadData}
/>