From 1f62f69485689a47bcf6065966b3c6f1bdb11fed 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 d57a67ea9ee84..d7cef13dcd074 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 @@ -116,6 +116,10 @@ export function getOrCreatePrefetchCacheEntry({ }) } +/* + * 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). + */ function prefixExistingPrefetchCacheEntry({ url, nextUrl, @@ -136,7 +140,7 @@ function prefixExistingPrefetchCacheEntry({ } /** - * 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, @@ -172,7 +176,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. */ 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 d99d420ddf3c5..6174924e85a14 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 @@ -143,7 +143,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() } @@ -196,7 +196,7 @@ function navigateReducer_noPPR( currentCache, cache, flightDataPath, - prefetchValues?.kind === 'auto' && + prefetchValues.kind === 'auto' && prefetchEntryCacheStatus === PrefetchCacheEntryStatus.reusable ) @@ -312,7 +312,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() } @@ -449,7 +449,7 @@ function navigateReducer_PPR( currentCache, cache, flightDataPath, - prefetchValues?.kind === 'auto' && + prefetchValues.kind === 'auto' && prefetchEntryCacheStatus === PrefetchCacheEntryStatus.reusable )