Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
dc11d77b
Unverified
Commit
dc11d77b
authored
Sep 19, 2022
by
Tim Neutkens
Committed by
GitHub
Sep 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure smooth scroll is disabled for navigation in new and existing router (#40642)
parent
c742c038
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
3 deletions
+19
-3
layout-router.client.tsx
packages/next/client/components/layout-router.client.tsx
+4
-0
index.tsx
packages/next/client/index.tsx
+4
-0
router.ts
packages/next/shared/lib/router/router.ts
+11
-3
No files found.
packages/next/client/components/layout-router.client.tsx
View file @
dc11d77b
...
...
@@ -167,7 +167,11 @@ export function InnerLayoutRouter({
focusAndScrollElementRef
.
current
.
focus
()
// Only scroll into viewport when the layout is not visible currently.
if
(
!
topOfElementInViewport
(
focusAndScrollElementRef
.
current
))
{
const
htmlElement
=
document
.
documentElement
const
existing
=
htmlElement
.
style
.
scrollBehavior
htmlElement
.
style
.
scrollBehavior
=
'auto'
focusAndScrollElementRef
.
current
.
scrollIntoView
()
htmlElement
.
style
.
scrollBehavior
=
existing
}
}
},
[
focusAndScrollRef
])
...
...
packages/next/client/index.tsx
View file @
dc11d77b
...
...
@@ -688,7 +688,11 @@ function doRender(input: RenderRouteInfo): Promise<any> {
}
if
(
input
.
scroll
)
{
const
htmlElement
=
document
.
documentElement
const
existing
=
htmlElement
.
style
.
scrollBehavior
htmlElement
.
style
.
scrollBehavior
=
'auto'
window
.
scrollTo
(
input
.
scroll
.
x
,
input
.
scroll
.
y
)
htmlElement
.
style
.
scrollBehavior
=
existing
}
}
...
...
packages/next/shared/lib/router/router.ts
View file @
dc11d77b
...
...
@@ -655,6 +655,14 @@ interface FetchNextDataParams {
unstable_skipClientCache
?:
boolean
}
function
handleSmoothScroll
(
fn
:
()
=>
void
)
{
const
htmlElement
=
document
.
documentElement
const
existing
=
htmlElement
.
style
.
scrollBehavior
htmlElement
.
style
.
scrollBehavior
=
'auto'
fn
()
htmlElement
.
style
.
scrollBehavior
=
existing
}
function
tryToParseAsJSON
(
text
:
string
)
{
try
{
return
JSON
.
parse
(
text
)
...
...
@@ -2141,7 +2149,7 @@ export default class Router implements BaseRouter {
// Scroll to top if the hash is just `#` with no value or `#top`
// To mirror browsers
if
(
hash
===
''
||
hash
===
'top'
)
{
window
.
scrollTo
(
0
,
0
)
handleSmoothScroll
(()
=>
window
.
scrollTo
(
0
,
0
)
)
return
}
...
...
@@ -2150,14 +2158,14 @@ export default class Router implements BaseRouter {
// First we check if the element by id is found
const
idEl
=
document
.
getElementById
(
rawHash
)
if
(
idEl
)
{
idEl
.
scrollIntoView
(
)
handleSmoothScroll
(()
=>
idEl
.
scrollIntoView
()
)
return
}
// If there's no element with the id, we check the `name` property
// To mirror browsers
const
nameEl
=
document
.
getElementsByName
(
rawHash
)[
0
]
if
(
nameEl
)
{
nameEl
.
scrollIntoView
(
)
handleSmoothScroll
(()
=>
nameEl
.
scrollIntoView
()
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment