MCPcopy
hub / github.com/vercel/next.js / mountLinkInstance

Function mountLinkInstance

packages/next/src/client/components/links.ts:158–194  ·  view source on GitHub ↗
(
  element: LinkElement,
  href: string,
  router: AppRouterInstance,
  fetchStrategy: PrefetchTaskFetchStrategy,
  prefetchEnabled: boolean,
  setOptimisticLinkStatus: (status: { pending: boolean }) => void
)

Source from the content-addressed store, hash-verified

156}
157
158export function mountLinkInstance(
159 element: LinkElement,
160 href: string,
161 router: AppRouterInstance,
162 fetchStrategy: PrefetchTaskFetchStrategy,
163 prefetchEnabled: boolean,
164 setOptimisticLinkStatus: (status: { pending: boolean }) => void
165): LinkInstance {
166 if (prefetchEnabled) {
167 const prefetchURL = coercePrefetchableUrl(href)
168 if (prefetchURL !== null) {
169 const instance: PrefetchableLinkInstance = {
170 router,
171 fetchStrategy,
172 isVisible: false,
173 prefetchTask: null,
174 prefetchHref: prefetchURL.href,
175 setOptimisticLinkStatus,
176 }
177 // We only observe the link's visibility if it's prefetchable. For
178 // example, this excludes links to external URLs.
179 observeVisibility(element, instance)
180 return instance
181 }
182 }
183 // If the link is not prefetchable, we still create an instance so we can
184 // track its optimistic state (i.e. useLinkStatus).
185 const instance: NonPrefetchableLinkInstance = {
186 router,
187 fetchStrategy,
188 isVisible: false,
189 prefetchTask: null,
190 prefetchHref: null,
191 setOptimisticLinkStatus,
192 }
193 return instance
194}
195
196export function mountFormInstance(
197 element: HTMLFormElement,

Callers 1

LinkComponentFunction · 0.90

Calls 2

coercePrefetchableUrlFunction · 0.85
observeVisibilityFunction · 0.85

Tested by

no test coverage detected