skip to content

Session & Request Context

Per-request facts a render needs — the session read from a cookie, the signed-in user — and where that read belongs, since a render cannot set a cookie. Asked because personal output breaks caching.

on this pageshow

questions

5

Five nested segments each ask for the signed-in user while rendering one page — how does that stay a single lookup?

level: middleimportance: should knowfreq 52%

basics

~20 s

A request-scoped memo: the first call performs the lookup, stores the in-flight result under the current request, and every later call in that render reuses it. The entry dies with the request, so nothing carries over to the next visitor.

open as a page

A signed-out visitor requests a deep personalised URL — how do you send them to sign-in and back afterwards?

level: seniorimportance: should knowfreq 55%

basics

~20 s

Capture the requested path and query, redirect to the sign-in route carrying it, and after a successful sign-in redirect there only if it is a local relative path; otherwise fall back to a default destination.

open as a page

Should the per-request session read run before routing, in a layout, or in each route module, and how do you decide?

level: principalimportance: should knowfreq 45%

basics

~20 s

Each site buys something different: a pre-routing step is uniform but coarse and cannot hand data to the route, a layout renders shared chrome, and a per-route read is explicit and precise. Most real apps use all three deliberately.

open as a page