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' ...@@ -33,7 +33,7 @@ import { fetchServerResponse } from './router-reducer/fetch-server-response'
import { unresolvedThenable } from './unresolved-thenable' import { unresolvedThenable } from './unresolved-thenable'
import { ErrorBoundary } from './error-boundary' import { ErrorBoundary } from './error-boundary'
import { matchSegment } from './match-segments' 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 { RedirectBoundary } from './redirect-boundary'
import { HTTPAccessFallbackBoundary } from './http-access-fallback/error-boundary' import { HTTPAccessFallbackBoundary } from './http-access-fallback/error-boundary'
import { createRouterCacheKey } from './router-reducer/create-router-cache-key' import { createRouterCacheKey } from './router-reducer/create-router-cache-key'
...@@ -244,7 +244,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr ...@@ -244,7 +244,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
focusAndScrollRef.hashFragment = null focusAndScrollRef.hashFragment = null
focusAndScrollRef.segmentPaths = [] focusAndScrollRef.segmentPaths = []
handleSmoothScroll( disableSmoothScrollDuringRouteTransition(
() => { () => {
// In case of hash scroll, we only need to scroll the element into view // In case of hash scroll, we only need to scroll the element into view
if (hashFragment) { if (hashFragment) {
...@@ -281,7 +281,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr ...@@ -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 focusAndScrollRef.onlyHashChange = false
// Set focus on the element // Set focus on the element
......
...@@ -14,7 +14,7 @@ import { HeadManagerContext } from '../shared/lib/head-manager-context.shared-ru ...@@ -14,7 +14,7 @@ import { HeadManagerContext } from '../shared/lib/head-manager-context.shared-ru
import mitt from '../shared/lib/mitt' import mitt from '../shared/lib/mitt'
import type { MittEmitter } from '../shared/lib/mitt' import type { MittEmitter } from '../shared/lib/mitt'
import { RouterContext } from '../shared/lib/router-context.shared-runtime' 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 { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import { import {
urlQueryToSearchParams, urlQueryToSearchParams,
...@@ -770,7 +770,7 @@ function doRender(input: RenderRouteInfo): Promise<any> { ...@@ -770,7 +770,7 @@ function doRender(input: RenderRouteInfo): Promise<any> {
if (input.scroll) { if (input.scroll) {
const { x, y } = input.scroll const { x, y } = input.scroll
handleSmoothScroll(() => { disableSmoothScrollDuringRouteTransition(() => {
window.scrollTo(x, y) window.scrollTo(x, y)
}) })
} }
......
...@@ -41,7 +41,7 @@ import { isLocalURL } from './utils/is-local-url' ...@@ -41,7 +41,7 @@ import { isLocalURL } from './utils/is-local-url'
import { isBot } from './utils/is-bot' import { isBot } from './utils/is-bot'
import { omit } from './utils/omit' import { omit } from './utils/omit'
import { interpolateAs } from './utils/interpolate-as' 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 type { Params } from '../../../server/request/params'
import { MATCHED_PATH_HEADER } from '../../../lib/constants' import { MATCHED_PATH_HEADER } from '../../../lib/constants'
...@@ -2286,7 +2286,7 @@ export default class Router implements BaseRouter { ...@@ -2286,7 +2286,7 @@ export default class Router implements BaseRouter {
scrollToHash(as: string): void { scrollToHash(as: string): void {
const [, hash = ''] = as.split('#', 2) const [, hash = ''] = as.split('#', 2)
handleSmoothScroll( disableSmoothScrollDuringRouteTransition(
() => { () => {
// Scroll to top if the hash is just `#` with no value or `#top` // Scroll to top if the hash is just `#` with no value or `#top`
// To mirror browsers // To mirror browsers
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Run function with `scroll-behavior: auto` applied to `<html/>`. * Run function with `scroll-behavior: auto` applied to `<html/>`.
* This css change will be reverted after the function finishes. * This css change will be reverted after the function finishes.
*/ */
export function handleSmoothScroll( export function disableSmoothScrollDuringRouteTransition(
fn: () => void, fn: () => void,
options: { dontForceLayout?: boolean; onlyHashChange?: boolean } = {} 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