-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Segment Cache feature check to
prefetch
API
Wraps the `prefetch` API in a feature check for the Segment Cache, and forwards the call to a stub for the new implementation. Unlike the old implementation, the Segment Cache doesn't store its data in the router reducer state; it writes into a global mutable cache. So we don't need to dispatch a router action. Since the Segment Cache isn't actually implemented yet, this effectively disables prefetching when the experimental flag is enabled. There's some validation that we do for prefetch URLs that I extracted into a shared function. (For example, we only prefetch same-origin URLs, and we don't prefetch anything in development.)
- Loading branch information
Showing
3 changed files
with
90 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/next/src/client/components/segment-cache/prefetch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createPrefetchURL } from '../../components/app-router' | ||
|
||
/** | ||
* Entrypoint for prefetching a URL into the Segment Cache. | ||
* @param href - The URL to prefetch. Typically this will come from a <Link>, | ||
* or router.prefetch. It must be validated before we attempt to prefetch it. | ||
*/ | ||
export function prefetch(href: string) { | ||
const url = createPrefetchURL(href) | ||
if (url === null) { | ||
// This href should not be prefetched. | ||
return | ||
} | ||
|
||
// TODO: Not yet implemented | ||
} |