Skip to content

Commit d151c1f

Browse files
feat(web): add scroll position restoration for changelog sidebar (#2166)
* feat(web): add scroll position restoration for changelog sidebar - Create useScrollRestoration hook for nested scrollable containers - Apply hook to changelog sidebar to restore scroll position when navigating between versions - TanStack Router's scrollRestoration only handles window scroll, this hook handles nested containers Co-Authored-By: yujonglee <[email protected]> * refactor(web): use resetScroll: false pattern for changelog navigation - Replace custom useScrollRestoration hook with useNavigate resetScroll: false - Follow the same pattern used in about.tsx and brand.tsx - Remove unused useScrollRestoration hook file - Convert Link to button with navigate for proper scroll handling Co-Authored-By: yujonglee <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: yujonglee <[email protected]>
1 parent 9541c6b commit d151c1f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

apps/web/src/routes/_view/changelog/$slug.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MDXContent } from "@content-collections/mdx/react";
22
import { Icon } from "@iconify-icon/react";
3-
import { createFileRoute, Link, notFound } from "@tanstack/react-router";
3+
import { createFileRoute, notFound, useNavigate } from "@tanstack/react-router";
44
import { ChevronDown, ChevronLeft, ChevronRight, Menu, X } from "lucide-react";
55
import { AnimatePresence, motion } from "motion/react";
66
import { useEffect, useState } from "react";
@@ -402,6 +402,7 @@ function ChangelogSidebar({
402402
allChangelogs: ChangelogWithMeta[];
403403
onNavigate?: () => void;
404404
}) {
405+
const navigate = useNavigate({ from: Route.fullPath });
405406
const [currentPage, setCurrentPage] = useState(0);
406407

407408
const versionGroups = groupVersions(allChangelogs);
@@ -422,6 +423,15 @@ function ChangelogSidebar({
422423
}
423424
};
424425

426+
const handleVersionClick = (slug: string) => {
427+
navigate({
428+
to: "/changelog/$slug",
429+
params: { slug },
430+
resetScroll: false,
431+
});
432+
onNavigate?.();
433+
};
434+
425435
return (
426436
<div className="h-full flex flex-col">
427437
<div className="flex-1 p-4 overflow-y-auto">
@@ -440,13 +450,11 @@ function ChangelogSidebar({
440450
: "/api/images/icons/stable-icon.png";
441451

442452
return (
443-
<Link
453+
<button
444454
key={version.slug}
445-
to="/changelog/$slug"
446-
params={{ slug: version.slug }}
447-
onClick={onNavigate}
455+
onClick={() => handleVersionClick(version.slug)}
448456
className={cn([
449-
"bg-stone-50 border rounded-lg p-3 hover:border-stone-400 hover:bg-stone-100 transition-colors flex items-center gap-3",
457+
"w-full bg-stone-50 border rounded-lg p-3 hover:border-stone-400 hover:bg-stone-100 transition-colors flex items-center gap-3 cursor-pointer",
450458
version.slug === changelog.slug
451459
? "border-stone-600 bg-stone-100"
452460
: "border-neutral-200",
@@ -461,15 +469,15 @@ function ChangelogSidebar({
461469
className="w-10 h-10"
462470
/>
463471
</div>
464-
<div className="flex-1 min-w-0">
472+
<div className="flex-1 min-w-0 text-left">
465473
<p className="text-sm font-medium text-stone-600 truncate">
466474
v{version.version}
467475
</p>
468476
<p className="text-xs text-neutral-500">
469477
{isPrerelease ? "Nightly" : "Stable"}
470478
</p>
471479
</div>
472-
</Link>
480+
</button>
473481
);
474482
})}
475483
</div>

0 commit comments

Comments
 (0)