Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/src/client/app-dir/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useMergedRef } from '../use-merged-ref'
import { isAbsoluteUrl } from '../../shared/lib/utils'
import { addBasePath } from '../add-base-path'
import { warnOnce } from '../../shared/lib/utils/warn-once'
import { ScrollBehavior } from '../components/router-reducer/router-reducer-types'
import type { PENDING_LINK_STATUS } from '../components/links'
import {
IDLE_LINK_STATUS,
Expand Down Expand Up @@ -307,7 +308,7 @@ function linkClicked(
dispatchNavigateAction(
href,
replace ? 'replace' : 'push',
scroll ?? true,
scroll === false ? ScrollBehavior.NoScroll : ScrollBehavior.Default,
linkInstanceRef.current,
transitionTypes
)
Expand Down
20 changes: 14 additions & 6 deletions packages/next/src/client/components/app-router-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type NavigateAction,
ACTION_HMR_REFRESH,
PrefetchKind,
ScrollBehavior,
type AppHistoryState,
} from './router-reducer/router-reducer-types'
import { reducer } from './router-reducer/router-reducer'
Expand Down Expand Up @@ -277,7 +278,7 @@ function getProfilingHookForOnNavigationStart() {
export function dispatchNavigateAction(
href: string,
navigateType: NavigateAction['navigateType'],
shouldScroll: boolean,
scrollBehavior: ScrollBehavior,
linkInstanceRef: LinkInstance | null,
transitionTypes: string[] | undefined
): void {
Expand Down Expand Up @@ -307,7 +308,7 @@ export function dispatchNavigateAction(
url,
isExternalUrl: isExternalURL(url),
locationSearch: location.search,
shouldScroll,
scrollBehavior,
navigateType,
})
}
Expand Down Expand Up @@ -356,7 +357,10 @@ function gesturePush(href: string, options?: NavigateOptions): void {

// Fork the router state for the duration of the gesture transition.
const currentUrl = new URL(state.canonicalUrl, location.href)
const shouldScroll = options?.scroll ?? true
const scrollBehavior =
options?.scroll === false
? ScrollBehavior.NoScroll
: ScrollBehavior.Default
// This is a special freshness policy that prevents dynamic requests from
// being spawned. During the gesture, we should only show the cached
// prefetched UI, not dynamic data.
Expand All @@ -373,7 +377,7 @@ function gesturePush(href: string, options?: NavigateOptions): void {
state.tree,
state.nextUrl,
freshnessPolicy,
shouldScroll,
scrollBehavior,
'push'
)
dispatchGestureState(forkedGestureState)
Expand Down Expand Up @@ -442,7 +446,9 @@ export const publicAppRouterInstance: AppRouterInstance = {
dispatchNavigateAction(
href,
'replace',
options?.scroll ?? true,
options?.scroll === false
? ScrollBehavior.NoScroll
: ScrollBehavior.Default,
null,
options?.transitionTypes
)
Expand All @@ -458,7 +464,9 @@ export const publicAppRouterInstance: AppRouterInstance = {
dispatchNavigateAction(
href,
'push',
options?.scroll ?? true,
options?.scroll === false
? ScrollBehavior.NoScroll
: ScrollBehavior.Default,
null,
options?.transitionTypes
)
Expand Down
Loading
Loading