skip to content

In a web email client, how do you decide which state is tied to the current route and which the app shell holds across navigation?

level: middleimportance: should knowfreq 44%

answer

  1. two lifetimes: the screen, the session
  2. navigate away, Back, reload, share
  3. the draft outlives the folder
  4. the selection belongs to the address
  5. shell state needs an owner and a key

basics

~20 s

Ask what the user expects after navigating away, pressing Back, reloading or sharing a link. The open thread and filters are route-keyed, in the address; a minimised draft, a sent notice and the layout preference are shell-held.

solid answer

~50 s

**Route-keyed** state belongs to one screen: it is created when the route is entered and discarded, or restored from the address, when the user leaves and returns. **Shell-held** state lives above the routes and survives moving between them. I decide by four tests: after navigating away, after Back, after a reload, and in a shared link, should this still be here? For the email client the open thread, the folder and the search filters are route-keyed and written to the address, so reload and Back restore them. The minimised compose draft is shell-held, owned by the compose feature and saved to the server as a draft, because the user expects it to stay while they read other folders. A "message sent, undo" notice is shell-held for the same reason. Getting one wrong is visible at once: a draft that vanishes on a folder change, or a selection a reload forgets.

go deeper

for a junior

Recall the two lifetimes: state that belongs to the current screen and state the app keeps while the user moves between screens.

for a middle

Apply the four tests to the email client and place the open thread, the filters and the minimised draft, saying which test decided each.

for a senior

Name the obligations shell-held state brings: an owner, a key per instance, a durable server copy, a limit, a clear end. Explain what breaks when the draft or selection sits in the wrong lifetime.

for a principal

Decide the app-wide convention: what the shell is allowed to hold, who owns each shell slot, and how reproducible-from-the-address screens are protected as features grow.

## Two lifetimes in one app A single-page web app has at least two scopes that state can be attached to: - **Route-keyed state** is tied to the current screen and its address. It is created when the route is entered and discarded when the user leaves; if it must come back, the route rebuilds it from the address or from cached server data. - **Shell-held state** lives in the **app shell**, the part of the app that stays on screen across navigation (top bar, folder list, compose dock, notification area). It survives moving between routes and is lost only on reload unless it is also persisted. Which layout levels of a router stay mounted is a mechanism question with its own home. The **design** question is a product one: for each piece of state, which lifetime does the user expect? ## Four tests that decide it 1. **Navigate away and come back.** Should it still be there? If the user minimised a draft and opened another folder, yes: shell-held. 2. **Press Back.** Should the previous screen return as it was? The previously open thread should, so it belongs to the route and its history entry. 3. **Reload.** Should it survive? The open thread should; a dropdown that was open should not. 4. **Share the link or open it in a new tab.** Should the recipient see it? The thread, yes, if they have access; the sender's draft, never. A piece that passes tests 2 to 4 belongs in the **address**. A piece that passes test 1 but not 4 is **shell-held**. A piece that passes none is **local** to its component and can die with the route. ## The email client, decided | State | Lifetime | Home | Why | |---|---|---|---| | Current folder | route | address path | Back, reload, links | | Open thread id | route | address path | reload must reopen it; a link must open it | | Search filters | route | address query | reload and Back restore the result set | | Message-list scroll position | route, per history entry | restored per history entry on Back | Back returns to the same place; not worth a link | | Minimised compose draft | session | shell, owned by compose; server draft | survives folder changes; private | | "Message sent, undo" notice | session, briefly | shell notification area | must survive the jump back to the inbox | | Reading-pane layout | across visits | shell, persisted | a preference, not a place | | Reply box text inside a thread | route, then saved as a draft | the route, saved to the server as a draft on leave | belongs to that thread; must not be lost | The last row shows that "route-keyed" does not mean "discarded". Leaving a thread with a half-written reply should either save it as a server draft or ask first; silently dropping it is the bug. ## The minimised draft: why the shell, and what it costs The draft is the clearest shell-held case, and it carries obligations: - **An owner.** The compose feature owns the draft state; other features may open or focus it but do not write its fields. - **A key.** Drafts are keyed by draft id, so two minimised drafts do not overwrite each other. - **A durable copy.** Shell state dies on reload, so the draft is autosaved to the server as a draft; the shell holds only the in-progress edit and the id. - **A limit.** The product decides how many drafts may be minimised at once and what happens at the limit. - **A clear end.** Sending, discarding and signing out remove it from the shell. Putting the draft in the folder route instead makes it disappear the moment the user opens another folder. Putting its text in the address makes private text part of history and of any link the user copies. ## Common mistakes - Holding the open thread only in shell memory: everything looks right until the first reload or Back press. - Holding everything in the shell "to be safe": a filter chosen in one folder leaks into the next, and screens stop being reproducible from their address. - Treating route-keyed as disposable: losing a half-written reply on navigation. - Forgetting that shell-held is not durable: a minimised draft with no server copy is lost on reload. In the round, run the four tests aloud on three or four items and the interviewer will see the rule rather than a list of answers.

  • Product asks that the open thread survive a reload but not appear in shared links. Where does it go?
    That combination rules out the address, which is what links share. It could go in `sessionStorage`, which is partitioned per tab and per origin, survives reloading that tab and is destroyed when the tab closes, so it never travels in a link. The cost is that a pasted link opens the folder without the thread, and a second tab starts empty. Most products accept the link instead.
  • The user opens a second draft while one is minimised. What does the shell-held design need?
    Drafts keyed by id rather than a single draft slot, a visible dock or tab per draft, and a product limit on how many can be open. Each draft autosaves to the server separately, so reload restores the list of open drafts from the server and only the unsaved last few keystrokes are at risk.

  • Holds the open thread only in shell memory because it is faster than reading the address
  • Puts the compose draft text in the query string so a reload restores it
  • Keeps the minimised draft in the folder route's state
  • Assumes shell-held state survives a reload
  • Treats route-keyed state as safe to drop, including a half-written reply