Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove optimistic navigation behavior when prefetch is false #58413

Merged
merged 14 commits into from
Nov 16, 2023
Merged
17 changes: 3 additions & 14 deletions packages/next/src/client/components/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,14 @@ function useChangeByServerResponse(

function useNavigate(dispatch: React.Dispatch<ReducerActions>): RouterNavigate {
return useCallback(
(href, navigateType, forceOptimisticNavigation, shouldScroll) => {
(href, navigateType, shouldScroll) => {
const url = new URL(addBasePath(href), location.href)

return dispatch({
type: ACTION_NAVIGATE,
url,
isExternalUrl: isExternalURL(url),
locationSearch: location.search,
forceOptimisticNavigation,
shouldScroll: shouldScroll ?? true,
navigateType,
cache: createEmptyCacheNode(),
Expand Down Expand Up @@ -330,22 +329,12 @@ function Router({
},
replace: (href, options = {}) => {
startTransition(() => {
navigate(
href,
'replace',
Boolean(options.forceOptimisticNavigation),
options.scroll ?? true
)
navigate(href, 'replace', options.scroll ?? true)
})
},
push: (href, options = {}) => {
startTransition(() => {
navigate(
href,
'push',
Boolean(options.forceOptimisticNavigation),
options.scroll ?? true
)
navigate(href, 'push', options.scroll ?? true)
})
},
refresh: () => {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export function fillCacheWithDataProperty(
newCache: CacheNode,
existingCache: CacheNode,
flightSegmentPath: FlightSegmentPath,
fetchResponse: () => Promise<FetchServerResponseResult>,
bailOnParallelRoutes: boolean = false
): { bailOptimistic: boolean } | undefined {
fetchResponse: () => Promise<FetchServerResponseResult>
): void {
const isLastEntry = flightSegmentPath.length <= 2

const [parallelRouteKey, segment] = flightSegmentPath
Expand All @@ -22,24 +21,14 @@ export function fillCacheWithDataProperty(
const existingChildSegmentMap =
existingCache.parallelRoutes.get(parallelRouteKey)

if (
!existingChildSegmentMap ||
(bailOnParallelRoutes && existingCache.parallelRoutes.size > 1)
) {
// Bailout because the existing cache does not have the path to the leaf node
// or the existing cache has multiple parallel routes
// Will trigger lazy fetch in layout-router because of missing segment
return { bailOptimistic: true }
}

let childSegmentMap = newCache.parallelRoutes.get(parallelRouteKey)

if (!childSegmentMap || childSegmentMap === existingChildSegmentMap) {
childSegmentMap = new Map(existingChildSegmentMap)
newCache.parallelRoutes.set(parallelRouteKey, childSegmentMap)
}

const existingChildCacheNode = existingChildSegmentMap.get(cacheKey)
const existingChildCacheNode = existingChildSegmentMap?.get(cacheKey)
let childCacheNode = childSegmentMap.get(cacheKey)

// In case of last segment start off the fetch at this level and don't copy further down.
Expand Down
Loading
Loading