(
element: LinkElement,
href: string,
router: AppRouterInstance,
fetchStrategy: PrefetchTaskFetchStrategy,
prefetchEnabled: boolean,
setOptimisticLinkStatus: (status: { pending: boolean }) => void
)
| 156 | } |
| 157 | |
| 158 | export 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 | |
| 196 | export function mountFormInstance( |
| 197 | element: HTMLFormElement, |
no test coverage detected