Skip to content

Commit 61b285e

Browse files
authored
Generalize Segment Cache fallback implementation (#84652)
This is a stack of refactors related to the internal map type used to store Segment Cache entries on the client. Refer to each commit message for full details. The main motivation is to generalize the "fallback entry" mechanism used for interception routes to more kinds of params. Currently this is only used for interception routes and search params, but in the future we will use it for route params, too.
1 parent a99aaa9 commit 61b285e

File tree

7 files changed

+866
-692
lines changed

7 files changed

+866
-692
lines changed

packages/next/src/client/components/segment-cache-impl/cache-key.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
type Opaque<K, T> = T & { __brand: K }
33

44
// Only functions in this module should be allowed to create CacheKeys.
5-
export type NormalizedHref = Opaque<'NormalizedHref', string>
5+
export type NormalizedPathname = Opaque<'NormalizedPathname', string>
66
export type NormalizedSearch = Opaque<'NormalizedSearch', string>
77
export type NormalizedNextUrl = Opaque<'NormalizedNextUrl', string>
88

99
export type RouteCacheKey = Opaque<
1010
'RouteCacheKey',
1111
{
12-
href: NormalizedHref
12+
pathname: NormalizedPathname
1313
search: NormalizedSearch
1414
nextUrl: NormalizedNextUrl | null
1515

@@ -21,11 +21,9 @@ export function createCacheKey(
2121
originalHref: string,
2222
nextUrl: string | null
2323
): RouteCacheKey {
24-
// TODO: We should remove the hash from the href and track that separately.
25-
// There's no reason to vary route entries by hash.
2624
const originalUrl = new URL(originalHref)
2725
const cacheKey = {
28-
href: originalHref as NormalizedHref,
26+
pathname: originalUrl.pathname as NormalizedPathname,
2927
search: originalUrl.search as NormalizedSearch,
3028
nextUrl: nextUrl as NormalizedNextUrl | null,
3129
} as RouteCacheKey

0 commit comments

Comments
 (0)