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
ba19ce37
Unverified
Commit
ba19ce37
authored
Dec 07, 2022
by
Jan Kaifer
Committed by
GitHub
Dec 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Force reflow when setting scrollBehavior (#43673)
fixes
https://github.com/vercel/next.js/issues/40719
parent
bd9148d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
0 deletions
+12
-0
layout-router.tsx
packages/next/client/components/layout-router.tsx
+4
-0
index.tsx
packages/next/client/index.tsx
+4
-0
router.ts
packages/next/shared/lib/router/router.ts
+4
-0
No files found.
packages/next/client/components/layout-router.tsx
View file @
ba19ce37
...
@@ -127,6 +127,10 @@ class ScrollAndFocusHandler extends React.Component<{
...
@@ -127,6 +127,10 @@ class ScrollAndFocusHandler extends React.Component<{
const
htmlElement
=
document
.
documentElement
const
htmlElement
=
document
.
documentElement
const
existing
=
htmlElement
.
style
.
scrollBehavior
const
existing
=
htmlElement
.
style
.
scrollBehavior
htmlElement
.
style
.
scrollBehavior
=
'auto'
htmlElement
.
style
.
scrollBehavior
=
'auto'
// In Chrome-based browsers we need to force reflow before calling `scrollTo`.
// Otherwise it will not pickup the change in scrollBehavior
// More info here: https://github.com/vercel/next.js/issues/40719#issuecomment-1336248042
htmlElement
.
getClientRects
()
domNode
.
scrollIntoView
()
domNode
.
scrollIntoView
()
htmlElement
.
style
.
scrollBehavior
=
existing
htmlElement
.
style
.
scrollBehavior
=
existing
}
}
...
...
packages/next/client/index.tsx
View file @
ba19ce37
...
@@ -697,6 +697,10 @@ function doRender(input: RenderRouteInfo): Promise<any> {
...
@@ -697,6 +697,10 @@ function doRender(input: RenderRouteInfo): Promise<any> {
const
htmlElement
=
document
.
documentElement
const
htmlElement
=
document
.
documentElement
const
existing
=
htmlElement
.
style
.
scrollBehavior
const
existing
=
htmlElement
.
style
.
scrollBehavior
htmlElement
.
style
.
scrollBehavior
=
'auto'
htmlElement
.
style
.
scrollBehavior
=
'auto'
// In Chrome-based browsers we need to force reflow before calling `scrollTo`.
// Otherwise it will not pickup the change in scrollBehavior
// More info here: https://github.com/vercel/next.js/issues/40719#issuecomment-1336248042
htmlElement
.
getClientRects
()
window
.
scrollTo
(
input
.
scroll
.
x
,
input
.
scroll
.
y
)
window
.
scrollTo
(
input
.
scroll
.
x
,
input
.
scroll
.
y
)
htmlElement
.
style
.
scrollBehavior
=
existing
htmlElement
.
style
.
scrollBehavior
=
existing
}
}
...
...
packages/next/shared/lib/router/router.ts
View file @
ba19ce37
...
@@ -659,6 +659,10 @@ function handleSmoothScroll(fn: () => void) {
...
@@ -659,6 +659,10 @@ function handleSmoothScroll(fn: () => void) {
const
htmlElement
=
document
.
documentElement
const
htmlElement
=
document
.
documentElement
const
existing
=
htmlElement
.
style
.
scrollBehavior
const
existing
=
htmlElement
.
style
.
scrollBehavior
htmlElement
.
style
.
scrollBehavior
=
'auto'
htmlElement
.
style
.
scrollBehavior
=
'auto'
// In Chrome-based browsers we need to force reflow before calling `scrollTo`.
// Otherwise it will not pickup the change in scrollBehavior
// More info here: https://github.com/vercel/next.js/issues/40719#issuecomment-1336248042
htmlElement
.
getClientRects
()
fn
()
fn
()
htmlElement
.
style
.
scrollBehavior
=
existing
htmlElement
.
style
.
scrollBehavior
=
existing
}
}
...
...
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