-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(ui): implement sidebar scroll position preservation #8517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ovflowd
merged 13 commits into
nodejs:main
from
malav2110:fix-selected-article-sidebar-scroll-fix
Jan 11, 2026
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0781979
feat(ui): implement sidebar scroll position preservation
malav2110 41e3879
fix: correct import statements for hooks in withSidebar component
malav2110 1ebf202
fix: correct comment grammar, improve sidebar component display name …
malav2110 ece53b4
fix: streamline imports in withSidebar component and update pathname …
malav2110 0f2b57b
fix: remove unused imports and ensure 'use client' directive is prese…
malav2110 0212fba
fix: replace useNavigationState with useScrollToElement in WithSideba…
malav2110 3e54d01
fix: clarify comment in handleScroll function to improve code readabi…
malav2110 9d06df5
fix: addressed nitpicks and ran pnpm version path in ui-components d…
malav2110 d021e51
Merge branch 'main' into fix-selected-article-sidebar-scroll-fix
malav2110 c723ccf
fix: remove unnecessary 'use client' directive from Sidebar component
malav2110 d3cb88b
Merge branch 'fix-selected-article-sidebar-scroll-fix' of https://git…
malav2110 48b3f00
fix: improve sidebar pathname handling
malav2110 ae02e18
fix: remove unused locale handling from WithSidebar component
malav2110 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export { default as useDetectOS } from './useDetectOS'; | ||
| export { default as useMediaQuery } from './useMediaQuery'; | ||
| export { default as useClientContext } from './useClientContext'; | ||
| export { default as useNavigationState } from './useNavigationState'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| 'use client'; | ||
|
|
||
| import { useCallback, useContext, useEffect, useRef } from 'react'; | ||
|
|
||
| import { NavigationStateContext } from '#site/providers/navigationStateProvider'; | ||
|
|
||
| import type { RefObject } from 'react'; | ||
|
|
||
| const useNavigationState = <T extends HTMLElement>( | ||
malav2110 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| id: string, | ||
malav2110 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ref: RefObject<T | null>, | ||
| debounceTime = 300 | ||
| ) => { | ||
| const navigationState = useContext(NavigationStateContext); | ||
| const timeoutRef = useRef<NodeJS.Timeout | null>(null); | ||
malav2110 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const handleScroll = useCallback(() => { | ||
malav2110 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (timeoutRef.current) { | ||
| clearTimeout(timeoutRef.current); | ||
| } | ||
|
|
||
| timeoutRef.current = setTimeout(() => { | ||
| if (ref.current) { | ||
| navigationState[id] = { | ||
| x: ref.current.scrollLeft, | ||
| y: ref.current.scrollTop, | ||
| }; | ||
| } | ||
| }, debounceTime); | ||
| }, [id, ref, navigationState, debounceTime]); | ||
|
|
||
| useEffect(() => { | ||
| const element = ref.current; | ||
malav2110 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (element) { | ||
| if (navigationState[id] && navigationState[id].y !== element.scrollTop) { | ||
| element.scroll({ top: navigationState[id].y, behavior: 'auto' }); | ||
| } | ||
|
|
||
| element.addEventListener('scroll', handleScroll, { passive: true }); | ||
|
|
||
| return () => { | ||
| element.removeEventListener('scroll', handleScroll); | ||
| // Clear any pending debounced calls | ||
| if (timeoutRef.current) { | ||
| clearTimeout(timeoutRef.current); | ||
| timeoutRef.current = null; | ||
malav2110 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }; | ||
| } | ||
| // We need this effect to run only on mount | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
| }; | ||
|
|
||
| export default useNavigationState; | ||
malav2110 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.