Client and server state
Keep server data in one cache, keep screen state in the address, and keep the rest local. Update the screen at once only when you can undo it.
- Required 2
- Recommended 9
Required
Key cached data by every input
APP-27Build every cache key from all the inputs that change the answer, including the account, the signed-in user, the filters, the sort and the page.
Keep tokens and sensitive data out of browser storage
APP-76Keep access tokens, passwords, card data, government ID numbers and health data out of
localStorage,sessionStorageand IndexedDB. Delete every draft and offline copy an account stored when it signs out.
Recommended
Keep server data in one cache
APP-26Keep data that comes from the server in one data-fetching cache, and read it from there on every screen. Never copy it into a global store or component state.
Show the answer to the latest request only
APP-28When a new request replaces an older one, such as a new search term, abort the older request and never render its answer.
Refresh every view a change touches
APP-29After a successful change, update or refetch every cached query that shows the changed record, including lists, counts and totals.
Undo optimistic updates that fail
APP-30When the screen changes before the server answers, keep a copy of the old data. If the request fails, put it back and say so in words. Refetch either way.
Keep screen state in the address
APP-31Put every choice that changes what a screen shows in the address, such as filters, sort, page, tab and the open record's random ID. Keep free-text search out of it when it may hold a name, email or phone number. Reloading or sharing the link shows the same screen.
Compute values instead of storing them
APP-32Compute totals, counts, filtered lists and labels from the source data when you render. Never keep them in their own state to update by hand.
Expect browser storage to fail or be cleared
APP-60Catch the error from every write to browser storage, and treat what is stored there as a copy that can vanish. Keep anything people cannot easily type again on the server too.
Pause polling in hidden tabs
APP-77Stop polling and refresh timers while the tab is hidden, and refresh once when it becomes visible again. A hidden tab sends 0 polling requests.
Return people to where they were on Back
APP-78In a single-page app, Back and Forward return people to the scroll position they left. A new navigation starts at the top of the new screen.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/app-ui/client-and-server-state">Agent Wranglers web app interface playbook</a>. In code you write, add a comment next to it with the same link.