fix: scroll to top on Link navigation with sticky headers#94093
Open
AliMahmoudDev wants to merge 2 commits into
Open
fix: scroll to top on Link navigation with sticky headers#94093AliMahmoudDev wants to merge 2 commits into
AliMahmoudDev wants to merge 2 commits into
Conversation
…rule Fixes vercel#53473 The no-html-link-for-pages rule was hardcoded to only match .js, .jsx, .ts, .tsx file extensions. When users configure custom pageExtensions in next.config.js (e.g. ['page.tsx', 'page.ts']), the rule would produce false positives/negatives. Changes: - Added pageExtensions support via eslint settings.next.pageExtensions - Modified parseUrlForPages and parseUrlForAppDir to accept custom extension regex patterns - Updated getUrlFromPagesDirectories and getUrlFromAppDirectory signatures to pass through extension regexes - Removed hardcoded TODO comments about page extensions support Usage in .eslintrc: settings: { next: { pageExtensions: ['page.tsx', 'page.ts'] } }
…64441) When a page has a sticky header and the scroll position is less than the header height, navigating via <Link> would not scroll to the top. This happened because topOfElementInViewport() only checked if the element's rect.top was within [0, viewportHeight], which returned true even when the document was not scrolled to position 0 (the sticky header's offset made the element appear to be in the viewport). The fix adds an additional check for htmlElement.scrollTop === 0 before exiting early. If the document is scrolled at all, we now always proceed with the scroll-to-top logic, ensuring pages with sticky headers scroll to top on navigation as expected. Applies to both InnerScrollAndFocusHandlerOld (class component) and InnerScrollHandlerNew (hook-based component with Fragment refs).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #64441
When a page has a position:sticky header and the scroll position is below zero but less than the header height, clicking a Link to navigate to another page does not scroll to the top.
Root cause: The topOfElementInViewport() early exit check returns true when the content element is visible, even with a non-zero scroll position. With sticky headers, the element rect.top can be positive at small scroll offsets.
Fix: Add an additional check that htmlElement.scrollTop === 0 before the early exit. This ensures scrolling always happens unless the page is truly at the top.