Unverified Commit 9a6f1bd4 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

rename `handleSmoothScroll` util (#81546)

This function has a confusing name because it doesn't do any sort of smooth scroll handling or behavior, it just resets smooth scroll handling on the document before performing a router transition.  This attempts to rename the function to be more accurate to what it's doing.
parent be7b3a64
......@@ -33,7 +33,7 @@ import { fetchServerResponse } from './router-reducer/fetch-server-response'
import { unresolvedThenable } from './unresolved-thenable'
import { ErrorBoundary } from './error-boundary'
import { matchSegment } from './match-segments'
import { handleSmoothScroll } from '../../shared/lib/router/utils/handle-smooth-scroll'
import { disableSmoothScrollDuringRouteTransition } from '../../shared/lib/router/utils/disable-smooth-scroll'
import { RedirectBoundary } from './redirect-boundary'
import { HTTPAccessFallbackBoundary } from './http-access-fallback/error-boundary'
import { createRouterCacheKey } from './router-reducer/create-router-cache-key'
......@@ -244,7 +244,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
focusAndScrollRef.hashFragment = null
focusAndScrollRef.segmentPaths = []
handleSmoothScroll(
disableSmoothScrollDuringRouteTransition(
() => {
// In case of hash scroll, we only need to scroll the element into view
if (hashFragment) {
......@@ -281,7 +281,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
}
)
// Mutate after scrolling so that it can be read by `handleSmoothScroll`
// Mutate after scrolling so that it can be read by `disableSmoothScrollDuringRouteTransition`
focusAndScrollRef.onlyHashChange = false
// Set focus on the element
......
......@@ -14,7 +14,7 @@ import { HeadManagerContext } from '../shared/lib/head-manager-context.shared-ru
import mitt from '../shared/lib/mitt'
import type { MittEmitter } from '../shared/lib/mitt'
import { RouterContext } from '../shared/lib/router-context.shared-runtime'
import { handleSmoothScroll } from '../shared/lib/router/utils/handle-smooth-scroll'
import { disableSmoothScrollDuringRouteTransition } from '../shared/lib/router/utils/disable-smooth-scroll'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import {
urlQueryToSearchParams,
......@@ -770,7 +770,7 @@ function doRender(input: RenderRouteInfo): Promise<any> {
if (input.scroll) {
const { x, y } = input.scroll
handleSmoothScroll(() => {
disableSmoothScrollDuringRouteTransition(() => {
window.scrollTo(x, y)
})
}
......
......@@ -41,7 +41,7 @@ import { isLocalURL } from './utils/is-local-url'
import { isBot } from './utils/is-bot'
import { omit } from './utils/omit'
import { interpolateAs } from './utils/interpolate-as'
import { handleSmoothScroll } from './utils/handle-smooth-scroll'
import { disableSmoothScrollDuringRouteTransition } from './utils/disable-smooth-scroll'
import type { Params } from '../../../server/request/params'
import { MATCHED_PATH_HEADER } from '../../../lib/constants'
......@@ -2286,7 +2286,7 @@ export default class Router implements BaseRouter {
scrollToHash(as: string): void {
const [, hash = ''] = as.split('#', 2)
handleSmoothScroll(
disableSmoothScrollDuringRouteTransition(
() => {
// Scroll to top if the hash is just `#` with no value or `#top`
// To mirror browsers
......
......@@ -2,7 +2,7 @@
* Run function with `scroll-behavior: auto` applied to `<html/>`.
* This css change will be reverted after the function finishes.
*/
export function handleSmoothScroll(
export function disableSmoothScrollDuringRouteTransition(
fn: () => void,
options: { dontForceLayout?: boolean; onlyHashChange?: boolean } = {}
) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment