Skip to content

Commit

Permalink
re-arrange some things
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Feb 7, 2024
1 parent 3ca5de0 commit ec7f968
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -197,7 +197,7 @@ function navigateReducer_noPPR(
currentCache,
cache,
flightDataPath,
prefetchValues?.kind === 'auto' &&
prefetchValues.kind === 'auto' &&
prefetchEntryCacheStatus === PrefetchCacheEntryStatus.reusable
)

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -451,7 +451,7 @@ function navigateReducer_PPR(
currentCache,
cache,
flightDataPath,
prefetchValues?.kind === 'auto' &&
prefetchValues.kind === 'auto' &&
prefetchEntryCacheStatus === PrefetchCacheEntryStatus.reusable
)

Expand Down

0 comments on commit ec7f968

Please sign in to comment.