Skip to content

Commit 48b3f00

Browse files
committed
fix: improve sidebar pathname handling
1 parent d3cb88b commit 48b3f00

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

apps/site/components/withSidebar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import Sidebar from '@node-core/ui-components/Containers/Sidebar';
4-
import { useTranslations } from 'next-intl';
4+
import { useLocale, useTranslations } from 'next-intl';
55
import { useRef } from 'react';
66

77
import Link from '#site/components/Link';
@@ -21,6 +21,7 @@ type WithSidebarProps = {
2121
const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
2222
const { getSideNavigation } = useSiteNavigation();
2323
const pathname = usePathname()!;
24+
const locale = useLocale();
2425
const t = useTranslations();
2526
const { push } = useRouter();
2627
const { frontmatter } = useClientContext();
@@ -44,7 +45,7 @@ const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
4445
<Sidebar
4546
ref={sidebarRef}
4647
groups={mappedSidebarItems}
47-
pathname={pathname}
48+
pathname={pathname.replace(`/${locale}`, '')}
4849
title={t('components.common.sidebar.title')}
4950
placeholder={frontmatter?.title}
5051
onSelect={push}

apps/site/hooks/client/useScrollToElement.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ const useScrollToElement = <T extends HTMLElement>(
1717

1818
// Restore scroll position on mount
1919
useEffect(() => {
20-
const element = ref.current;
21-
if (!element) {
20+
if (!ref.current) {
2221
return;
2322
}
2423

2524
// Restore scroll position if saved state exists
2625
const savedState = navigationState[id];
2726

2827
// Scroll only if the saved position differs from current
29-
if (savedState && savedState.y !== element.scrollTop) {
30-
element.scroll({ top: savedState.y, behavior: 'auto' });
28+
if (savedState && savedState.y !== ref.current.scrollTop) {
29+
ref.current.scroll({ top: savedState.y, behavior: 'auto' });
3130
}
3231
// navigationState is intentionally excluded
3332
// it's a stable object reference that doesn't need to trigger re-runs

0 commit comments

Comments
 (0)