InfiniteTail
HkInfiniteTail is the DOM half of the infinite-list scaffold: the thing you mount directly after the list body (inside whatever scroll viewport your page already owns — it never creates one) so the list has a bottom that either says "the next window is on its way", "there is more, scroll for it", or "that was everything". It renders one of four affordances chosen by state and mode: skeleton placeholder rows, an invisible sentinel that a page can observe, the explicit load-more button, or the count-carrying end note.
- This component is the tail only. The page state machine — which page is in flight, whether the walk is exhausted, how a failure is retried — is yours. The component's contract is that you derive state from your flags with the exact rule documented below.
- The strip it delegates to in manual mode and in the end state is LoadMore: the button, the spinner morph, the shown / total counter and the end sentence all belong to that component. This page describes the state machine around it; that page describes the chrome inside it.
- The placeholder rows are SkeletonList, built from the Skeleton atom. Match skeletonItemHeight to your real row height, or the list jumps when the real rows land.
- When the data is windowed rather than appended — a virtualised list that keeps a fixed scroll length and swaps rows in and out — the item wrapper is WindowedItem, and there is no tail at all: the scroll position, not a fetch, decides what is drawn.
- The snapshot is a still frame. Both forms render one of the four branches and nothing else; the sentinel's observer, the auto-fill re-check and the loadMore emissions are runtime behaviour that a static render does not perform. See the section on that below.
Import
;
use *; // InfiniteTail, InfiniteTailState, infinite_tail_state
use *; // InfiniteTailProps, rsx!, VNode, EventHandler
The Rust form is a plain function, InfiniteTail(InfiniteTailProps { … }); inside rsx! the element form is InfiniteTail { … } and every prop may be omitted. Vue's state string is the InfiniteTailState enum there — Idle (the default), Loading, End — and Vue's loadMore emit is on_load_more. Build the state with infinite_tail_state(exhausted, loading, loading_more) rather than by hand: that function is the documented derivation, ported verbatim.
Deriving the state
Bind exactly this, in this order:
state = exhausted ? "end" : (loading || loadingMore) ? "loading" : "idle"
exhausted wins over any in-flight flag. loading is the first page and loadingMore every later one; both must land on loading, because a first page that reports idle renders a sentinel over an empty list and a short first page never auto-fills. The mirror exports the same rule as infinite_tail_state, so a host that composes its own page machine cannot drift from the tail's branches.
The mirror also exports the state-to-affordance matrix as infinite_tail_affordance(state, auto) — the same four branches the Vue render function takes — plus infinite_tail_should_load(state, in_view), which is Vue's maybeLoad guard.
The four cards are the whole matrix. The first is auto plus loading: placeholder rows, no control, no text. The second is manual plus loading: the load-more button already wearing its spinner, so the affordance never disappears mid-request. The third is manual plus idle: the button. The fourth is the end note, identical in both modes.
Auto mode: the sentinel, its lookahead and its re-check
With auto (the default) and idle, the tail renders an invisible aria-hidden sentinel — a 1px sliver of layout with a stable rect — and an IntersectionObserver watches it inside the browser viewport, not inside any particular scroll element. That is what lets it work under a nested scroller without knowing which ancestor scrolls.
lookahead sets the runway before the sentinel reaches the viewport, in pixels: the observer's rootMargin becomes lookahead px 0px lookahead px 0px, so the zone extends above and below the viewport — a fast upward fling back into the zone counts too. The default is 480, about half a screen. Changing it live re-observes with the new margin.
Intersection alone misses the case where a page lands while the tail is still on screen: the observer does not re-fire without a geometry change. So every transition into idle re-checks the sentinel's rect on the next animation frame and keeps asking until the tail actually leaves the viewport. That is the auto-fill contract for short first screens, and it is the reason a fresh tail on an empty list fills itself without the user scrolling.
Rows the page already delivered. Scroll inside this box; the sentinel sits under the text.
label is a diagnostic hook, not an accessible name: it is stamped as data-label on the sentinel for tests and DOM inspection, and the sentinel stays aria-hidden because it is invisible geometry. The mirror adds a second such attribute, data-lookahead, so a host or a DOM test can read the threshold it is supposed to observe with — [D] that attribute has no Vue counterpart.
Manual mode, the end note and the emitted loadMore
auto={false} drops the sentinel entirely and renders the explicit button instead — the affordance is the control, and nothing fires on scroll. The end note renders in both modes.
loadMore fires from two places in Vue: the observer and the re-check both call the same guard, and the manual button calls it too. The guard is strict — the tail must be idle and, on the geometry path, in view — which gives you a documented non-feature: there is no auto-retry after a failed page. A failed page terminalizes the machine's walk; the tail keeps emitting loadMore as the sentinel re-enters view, and each emission is a no-op until the host calls its own reload verb, with the delivered rows left on screen under whatever stale banner the page draws. Auto-retrying from the tail would re-fire on a fixed geometry with no backoff, one request per round trip, which locks a shared rate budget — so it is refused by design rather than left as an accident.
In the Rust mirror the observer and the re-check do not exist (see below), so on_load_more fires only from the manual button's click, exactly like LoadMore's own emit.
The still frame, and what the mirror leaves to the host
A rendered example is one frame of a state machine, and this component's whole job is changing frames. In the snapshots above the auto tail shows either three placeholder rows or a 1px sliver; nothing observes anything, nothing re-checks, and no loadMore leaves the page — the browser behaviour arrives only when the component is mounted in a live document.
The Rust mirror cannot mount in that document either, and for a stronger reason: the vdom has no DOM lifecycle hooks. So there is no IntersectionObserver, no animation-frame re-check and no measurement. Instead the mirror exports the pure predicates a host needs to run its own observer and reach the same verdict:
- infinite_tail_root_margin(lookahead) — the rootMargin string, with the same above-and-below runway.
- infinite_tail_sentinel_in_view(…) — the rect arithmetic behind the re-check, including the zero-area early-out.
- infinite_tail_should_load(state, in_view) — the guard, i.e. the "no auto-retry" rule as code.
- infinite_tail_lookahead_px(lookahead) — the normalization: a negative or non-finite runway reads as 0 rather than inverting the zone.
The strings are not duplicated: the mirror's end note and button labels come from the LoadMore mirror under the same components.hk.loadMore.* i18n family, so the tail adds no key of its own.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| state | <code>String as PropType<"idle" | "loading" | "end"></code> | "idle" as const | — |
| auto | Boolean | true | — |
| shown | Number | undefined | — |
| total | Number | undefined | — |
| skeletonCount | Number | 3 | — |
| skeletonItemHeight | String | "40px" | — |
| lookahead | Number | 480 | — |
| label | String | undefined | — |
Emits
| Event | Payload |
|---|---|
| loadMore | — |
Rust
Props — InfiniteTail
| Prop | Type | Default | Description |
|---|---|---|---|
| state | InfiniteTailState | InfiniteTailState::Idle | The tail state (Vue state). |
| auto | bool | true | Auto-load on approach (default). |
| shown | Option<u32> | None | Delivered item count (with total, the progress counter). |
| total | Option<u32> | None | Match count behind the windowed list. |
| skeleton_count | u32 | 3 | Skeleton placeholder rows while a later page is in flight. |
| skeleton_item_height | String | "40px".to_string() | Row height of the skeleton placeholders (match the host's row height so the tail does not jump when real rows land). |
| lookahead | f64 | 480.0 | Viewport lookahead in px before the tail enters view (default 480). |
| label | Option<String> | None | Diagnostic hook rendered as data-label on the (aria-hidden) sentinel — for tests and DOM inspection, NOT an a11y name. |
| on_load_more | Option<EventHandler<()>> | None | The loadMore emit: fired by the manual affordance's click. |
Accessibility
- The skeleton tail is a role="status" region with aria-live="polite" wrapping a list that is aria-hidden, so a screen reader is told the list is still filling without walking a column of empty placeholder rows. Give the region its own busy text on the page (aria-busy on the list container) if the message needs to be more specific than "something is loading".
- The sentinel is aria-hidden and pointer-inert: it carries no name, no role and no stop. Its data-label is for tests and DOM inspection and is never announced — do not use it to convey anything to a user.
- The end note and the manual button are LoadMore's accessible elements: a role="status" sentence for the former, a named and aria-busy button for the latter. The tail changes which of them exists, and both are announced when they appear.
- Switching from skeleton rows to the end note swaps the live region's contents rather than appending to it, so the announcement is "exhausted", not a second copy of the list.
- Nothing in the tail is a tab stop in auto mode, so the keyboard path to more rows is the page's own scrolling; in manual mode the button is the only stop, which is the deliberate trade between the two modes.
Related components
- LoadMore — the strip this tail delegates to in manual mode and in the end state, with its counter and its end sentence.
- SkeletonList — the placeholder rows the auto tail draws while a page is in flight.
- CardList — the list surface the tail mounts after, and the owner of the empty state.
- WindowedItem — the other long-list strategy: reserve every item's height and swap contents, with no tail.
- Table — the tabular host, when the windowed data is columns rather than rows.