| | import { warnOnce } from '../../utils/warn-once' |
| |
|
| | |
| | |
| | |
| | |
| | export function disableSmoothScrollDuringRouteTransition( |
| | fn: () => void, |
| | options: { dontForceLayout?: boolean; onlyHashChange?: boolean } = {} |
| | ) { |
| | |
| | |
| | if (options.onlyHashChange) { |
| | fn() |
| | return |
| | } |
| |
|
| | const htmlElement = document.documentElement |
| | const hasDataAttribute = htmlElement.dataset.scrollBehavior === 'smooth' |
| |
|
| | |
| | |
| | |
| | if (process.env.__NEXT_OPTIMIZE_ROUTER_SCROLL) { |
| | if (!hasDataAttribute) { |
| | |
| | fn() |
| | return |
| | } |
| | } else { |
| | |
| |
|
| | |
| | if ( |
| | process.env.NODE_ENV === 'development' && |
| | !hasDataAttribute && |
| | getComputedStyle(htmlElement).scrollBehavior === 'smooth' |
| | ) { |
| | warnOnce( |
| | 'Detected `scroll-behavior: smooth` on the `<html>` element. In a future version, ' + |
| | 'Next.js will no longer automatically disable smooth scrolling during route transitions. ' + |
| | 'To prepare for this change, add `data-scroll-behavior="smooth"` to your <html> element. ' + |
| | 'Learn more: https://nextjs.org/docs/messages/missing-data-scroll-behavior' |
| | ) |
| | } |
| | } |
| |
|
| | |
| | const existing = htmlElement.style.scrollBehavior |
| | htmlElement.style.scrollBehavior = 'auto' |
| | if (!options.dontForceLayout) { |
| | |
| | |
| | |
| | htmlElement.getClientRects() |
| | } |
| | fn() |
| | htmlElement.style.scrollBehavior = existing |
| | } |
| |
|