In a mobile recipe feed thousands of items deep, what should the client save so a rebuild, a navigation back or a relaunch returns the reader to the same recipe?
answer
- a place is a card, not a distance
- the first visible item
- an id plus an offset within it
- rebuild the window around it
- neighbours as a fallback
basics
~20 sAn anchor: the id of the first visible item plus its edge's offset in the viewport, ideally with its neighbours' ids. Restore by rebuilding the list from the local store and placing that item, never by replaying a pixel offset or an index.
solid answer
~50 sIn a long, changing feed the reader's place is a card, not a distance from the top: inserts, removals, size corrections and evicted pages all move offsets and indexes. So save an **anchor** — the id of the first visible item and how far its top edge sits from the viewport's top — plus the ids just before and after it. A rebuild done by diffing stable ids leaves existing rows in place; a navigation back restores the anchor from the screen's state or from the store before the list is shown; a relaunch rebuilds the window from the local store and loads pages around the anchor, not from the first page. Saved UI state can carry the anchor across a kill but may be discarded, so persist the id cheaply too. If the anchor is gone, land on the nearest surviving neighbour, else the top.
go deeper
Recall that the place to restore is an item, saved as its id, and that a pixel offset or an index stops pointing at it once the list changes.
Explain the anchor — first visible item's id plus its offset — and why diffing by id, rather than replacing the list, keeps the place through a rebuild.
Restore after a relaunch from the local store and around the anchor, persist the ids because saved UI state can be discarded, and plan for a vanished anchor.
Weigh restoring the old place against starting fresh after a long absence, and keep the anchor mechanism able to serve whichever policy the product picks.
## What "the same place" means in a feed In a recipe feed thousands of items deep, the reader's place is "the card I was looking at", not a distance from the top. Three events put it at risk: - **a rebuild** — the screen's list is recomputed after new data, a setting change or a resize; - **a navigation back** — the reader opened a recipe and returns to the feed; - **a relaunch** — the process was ended in the background and the app starts again. Between the save and the restore, items above the reader may have been inserted, removed, resized or evicted from the local window. Whatever is saved has to point at the same card through all of that. ## Saving an anchor, not an offset | what is saved | after inserts above | after rows above change height | after rows above are evicted | |---|---|---|---| | pixel offset from the top | different content | different content | meaningless | | index of the first visible row | shifted by the number inserted | same row | shifted by the number evicted | | anchor id plus offset within it | same card | same card | same card while it exists | The **anchor** is the id of the first visible item plus the distance between its top edge and the viewport's top. Restoring it means finding that id in the rebuilt list and placing that row at the saved distance. Because the list is positioned by the anchor, estimated heights of rows above it no longer decide what the reader sees. This is also the shape platform guidance recommends for saved UI state: keep an identifier that locates the data, not a copy of the data. ## Restoring in each case 1. **Rebuild.** When the list is updated by diffing stable ids rather than replaced, existing rows stay where they are and nothing needs restoring, as long as nothing is inserted above the reader — that case is the refresh design's. A full replacement restores the anchor explicitly. 2. **Navigation back.** Keep the feed screen's state — its item window and the anchor — alive while the recipe screen is on top, or rebuild it from the local store; either way, place the anchor before the list is first shown. 3. **Relaunch.** The small saved-UI-state mechanism can carry the anchor across a process kill, but one platform's guidance says that state may be discarded at the system's discretion and is no substitute for data saved to disk. So persist the anchor's ids cheaply alongside the feed's stored window, rebuild the window from the local store, and load the pages around the anchor rather than starting from the first page. How the window and its cursors are reloaded belongs to the paging design. ## When the anchor is gone The anchor recipe may have been evicted from the local window, removed by the server or hidden by the user. Plan the fallbacks before they are needed: - save the ids just before and after the anchor too, and land on the nearest one that still exists; - if none survives, start at the top of the cached window rather than at an arbitrary offset; - never replay a saved pixel offset into a list whose contents changed — it lands on content that merely happens to be there. ## Pitfalls - **Restoring before the anchor's item is loaded** shows the top of the list and then jumps; show the cached window around the anchor first, and only then let fresh data merge in. - **Saving the records themselves** in saved UI state duplicates the store and bloats a mechanism meant for small values; ids are enough. - **Restoring an anchor into a different feed** — another account, another filter — lands on nothing meaningful; save the feed's identity with the anchor and ignore a mismatch. ## Where the boundaries are Which state tier holds what — memory, saved UI state, disk — and whether to restore at all after a swipe-away or a long absence are the app lifecycle's restore policy. Keeping the reader in place while fresh items are inserted above them is the refresh-and-merge design's job, and the toolkit's own call to scroll to an item is that toolkit's subject. The decision here is what identifies a place in a long list, and how to get back to it.
- Why save the ids around the anchor and not only the anchor itself?The anchor can disappear between save and restore — evicted, deleted or hidden. Its neighbours cost almost nothing to store and usually survive, so the reader lands one card away instead of at the top. Two or three ids are enough; saving the whole visible list adds little.
- Should a relaunch the next morning restore the old place at all?That is a product policy: many feeds start a long-absent reader at the newest items and offer a way back to where they were. The list design should support both — restore by anchor, or start at the top — and leave the choice, and how fresh items join, to the app's restore and refresh rules.
- Saving the scroll offset in pixels is enough to restore a feed.
- The first visible row's index identifies the reader's place across launches.
- Saved UI state is always kept, so nothing about the place needs persisting.
- If the anchor is gone, restoring the old pixel offset is a sound fallback.
- Returning to the old place requires reloading the feed from its first page.