-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: Links always scroll to URL hash on hover (#5930) #5944
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
birkskyum
merged 12 commits into
TanStack:main
from
Shreyas-Sarkar:fix/hash-hover-scroll
Nov 23, 2025
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a8916e5
fix: Links always scroll to URL hash on hover
Shreyas-Sarkar 367707d
added tests
Shreyas-Sarkar c3b1c0d
ci: apply automated fixes
autofix-ci[bot] 159a9ed
fix: add test pages for hash hover scroll test
Shreyas-Sarkar 7b1f05a
ci: apply automated fixes
autofix-ci[bot] 78b8887
fix: add test pages for hash hover scroll test
Shreyas-Sarkar ba6f74e
add test route hover-preload-hash
birkskyum 03ac986
use repro for testing
birkskyum ba3bf14
ci: apply automated fixes
autofix-ci[bot] e6eb4c6
use test id to locate element
birkskyum ed724fb
format
birkskyum a8fcb2e
format
birkskyum 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
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
38 changes: 38 additions & 0 deletions
38
e2e/react-router/basic-file-based/src/routes/(tests)/normal-page.tsx
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,38 @@ | ||
| import { createFileRoute, Link } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createFileRoute('/(tests)/normal-page')({ | ||
| component: NormalPage, | ||
| }) | ||
|
|
||
| function NormalPage() { | ||
| return ( | ||
| <div className="p-2"> | ||
| <h3>Normal Page</h3> | ||
|
|
||
| {/* Add the link that the test is looking for */} | ||
| <div style={{ marginBottom: '1rem' }}> | ||
| <Link to="/lazy-page" className="header-link"> | ||
| Head-/lazy-page | ||
| </Link> | ||
| </div> | ||
|
|
||
| <div style={{ height: '200vh' }}> | ||
| Scroll down to see the target element | ||
| </div> | ||
|
|
||
| <div | ||
| id="at-the-bottom" | ||
| data-testid="at-the-bottom" | ||
| style={{ | ||
| height: '100px', | ||
| background: '#f0f0f0', | ||
| border: '1px solid #ccc', | ||
| padding: '1rem', | ||
| marginTop: '2rem' | ||
| }} | ||
| > | ||
| This is the target element at the bottom of the page | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
e2e/react-router/basic-file-based/src/routes/lazy-page.tsx
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,14 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createFileRoute('/lazy-page')({ | ||
| component: LazyPage, | ||
| }) | ||
|
|
||
| function LazyPage() { | ||
| return ( | ||
| <div className="p-2"> | ||
| <h3>Lazy Loaded Page</h3> | ||
| <p>This page was loaded lazily.</p> | ||
| </div> | ||
| ) | ||
| } |
22 changes: 22 additions & 0 deletions
22
e2e/react-router/basic-file-based/tests/hover-preload-hash.spec.ts
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,22 @@ | ||
| import { expect, test } from '@playwright/test' | ||
| import { toRuntimePath } from '@tanstack/router-e2e-utils' | ||
|
|
||
| // This test guards against a regression where hovering (intent preload) | ||
| test('hovering links does not trigger hash scroll (no navigation)', async ({ | ||
| page, | ||
| }) => { | ||
| // Go to a page with a hash target at the bottom | ||
| await page.goto(toRuntimePath('/normal-page#at-the-bottom')) | ||
| await expect(page.getByTestId('at-the-bottom')).toBeInViewport() | ||
|
|
||
| // Scroll up so the hash target is no longer in view | ||
| await page.evaluate(() => window.scrollBy(0, -300)) | ||
| await expect(page.getByTestId('at-the-bottom')).not.toBeInViewport() | ||
|
|
||
| // Hover a header link to trigger intent preload (should NOT change scroll) | ||
| await page.getByRole('link', { name: 'Head-/lazy-page' }).hover() | ||
| await page.waitForTimeout(400) | ||
|
|
||
| // Ensure we did not jump back to the hash target | ||
| await expect(page.getByTestId('at-the-bottom')).not.toBeInViewport() | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
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.