You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 03661c0
Browse filesBrowse the repository at this point in the historyBrowse files
feat(pages): prefetch a visible Link only after it stays in view (#701)
A `'visible'` Link now prefetches only after it has been in view for 300
ms. Scrolling it out of view cancels the wait, and coming back restarts
it.
300 ms skips links scrolled past quickly in long lists, now that
`'visible'` can be the app-wide default.
Precedent:
[Astro](https://github.com/withastro/astro/blob/main/packages/astro/src/prefetch/index.ts)
debounces viewport prefetches by the same 300 ms, and [TanStack
Router](https://github.com/TanStack/router/blob/main/packages/react-router/src/link.tsx)
applies `preloadDelay` to viewport preloads, cancelling when the link
leaves the viewport.
Tests: fake-timer unit cases for the delay, cancel, restart, firing
once, and cleanup.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/guide/pages-routing/overview.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -350,7 +350,7 @@ Add `prefetch` to a `Link` to load its page before the user clicks, so the visit
350
350
</Link>
351
351
```
352
352
353
-
`prefetch` on its own loads the page on hover, keyboard focus, or touch. A `Link` can also prefetch on click, as soon as it renders, or when it scrolls into view, and `cacheFor` sets how long a prefetched page is reused. See [Prefetching](../../reference/api/pages.md#prefetching) for every option.
353
+
`prefetch` on its own loads the page on hover, keyboard focus, or touch. A `Link` can also prefetch on click, as soon as it renders, or once it stays in view, and `cacheFor` sets how long a prefetched page is reused. See [Prefetching](../../reference/api/pages.md#prefetching) for every option.
354
354
355
355
To give every `Link` a prefetch strategy, set `prefetch.defaultStrategy` in the adapter plugin. A `Link` that sets its own `prefetch` keeps it:
356
356
@@ -359,7 +359,7 @@ To give every `Link` a prefetch strategy, set `prefetch.defaultStrategy` in the
Prefer `'hover'` or `'click'` as the default. With `'mount'` or `'visible'`, every `Link` loads its page as soon as it renders or scrolls into view, including links in long lists.
362
+
Prefer `'hover'` or `'click'` as the default. With `'mount'` or `'visible'`, every `Link` loads its page once it renders or stays in view, which adds up in long lists.
363
363
364
364
Prefetching runs the destination's loader, so keep loaders free of side effects such as counting views.
|`'hover'` or `true`| When the pointer rests on the link for `hoverDelay`, when it gets keyboard focus, or on touch |
30
30
|`'click'`| When the mouse button or finger goes down, just before the click |
31
31
|`'mount'`| As soon as the link renders |
32
-
|`'visible'`|The first time the link scrolls into view |
32
+
|`'visible'`|Once the link has stayed in view for 300 ms. Links scrolled quickly past are skipped|
33
33
|`false`| Never |
34
34
35
35
With an array such as `['visible', 'hover']`, the first strategy to happen loads the page, and later ones reuse it. `prefetch` works only on GET links, and links to other sites are never prefetched.
0 commit comments