From ec7f968e1d4833ea790a35b4da673d6acb58487d Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Tue, 6 Feb 2024 18:22:07 -0800 Subject: [PATCH] re-arrange some things --- .../components/router-reducer/prefetch-cache-utils.ts | 8 ++++++-- .../router-reducer/reducers/navigate-reducer.ts | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/next/src/client/components/router-reducer/prefetch-cache-utils.ts b/packages/next/src/client/components/router-reducer/prefetch-cache-utils.ts index 53eb311580ea2..098eeea33cd6f 100644 --- a/packages/next/src/client/components/router-reducer/prefetch-cache-utils.ts +++ b/packages/next/src/client/components/router-reducer/prefetch-cache-utils.ts @@ -33,6 +33,10 @@ function createPrefetchCacheKey(url: URL, nextUrl?: string | null) { return pathnameFromUrl } +/** + * Used to take an existing cache entry and prefix it with the nextUrl, if it exists. + * This ensures that we don't have conflicting cache entries for the same URL (as is the case with route interception). + */ export function prefixExistingPrefetchCacheEntry({ url, nextUrl, @@ -142,7 +146,7 @@ export function getPrefetchCacheEntry({ } /** - * Use to seed the prefetch cache with an entry for already-resolved data + * Use to seed the prefetch cache with data that has already been fetched. */ export function createPrefetchEntry({ nextUrl, @@ -178,7 +182,7 @@ export function createPrefetchEntry({ } /** - * Creates a prefetch entry for data that has not been resolved. This will add the prefetch request to a promise queue. + * Creates a prefetch entry entry and enqueues a fetch request to retrieve the data. */ export function createLazyPrefetchEntry({ url, diff --git a/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts b/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts index d480298f4235e..cbbb11840428d 100644 --- a/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts +++ b/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts @@ -144,7 +144,7 @@ function navigateReducer_noPPR( return data.then( ([flightData, canonicalUrlOverride]) => { // we only want to mark this once - if (prefetchValues && !prefetchValues.lastUsedTime) { + if (!prefetchValues.lastUsedTime) { // important: we should only mark the cache node as dirty after we unsuspend from the call above prefetchValues.lastUsedTime = Date.now() } @@ -197,7 +197,7 @@ function navigateReducer_noPPR( currentCache, cache, flightDataPath, - prefetchValues?.kind === 'auto' && + prefetchValues.kind === 'auto' && prefetchEntryCacheStatus === PrefetchCacheEntryStatus.reusable ) @@ -314,7 +314,7 @@ function navigateReducer_PPR( return data.then( ([flightData, canonicalUrlOverride, _postponed]) => { // we only want to mark this once - if (prefetchValues && !prefetchValues.lastUsedTime) { + if (!prefetchValues.lastUsedTime) { // important: we should only mark the cache node as dirty after we unsuspend from the call above prefetchValues.lastUsedTime = Date.now() } @@ -451,7 +451,7 @@ function navigateReducer_PPR( currentCache, cache, flightDataPath, - prefetchValues?.kind === 'auto' && + prefetchValues.kind === 'auto' && prefetchEntryCacheStatus === PrefetchCacheEntryStatus.reusable )