Skip to content

Commit

Permalink
Added description of the hack that we did
Browse files Browse the repository at this point in the history
  • Loading branch information
jankaifer committed Dec 6, 2022
1 parent 6ba1f64 commit f0fff37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/next/client/index.tsx
Expand Up @@ -697,6 +697,9 @@ function doRender(input: RenderRouteInfo): Promise<any> {
const htmlElement = document.documentElement
const existing = htmlElement.style.scrollBehavior
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)
htmlElement.style.scrollBehavior = existing
Expand Down
3 changes: 3 additions & 0 deletions packages/next/shared/lib/router/router.ts
Expand Up @@ -659,6 +659,9 @@ function handleSmoothScroll(fn: () => void) {
const htmlElement = document.documentElement
const existing = htmlElement.style.scrollBehavior
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()
htmlElement.style.scrollBehavior = existing
Expand Down

0 comments on commit f0fff37

Please sign in to comment.