The Role Choice That Did Not Survive a Page Change
Role state in a static manual reset on every navigation; sessionStorage turned out to be the right storage tier, not localStorage.
TL;DR
Role selections reset on every sidebar click because the generator ships 26 standalone HTML pages, so DOM state dies with each page load. localStorage and URL parameters were rejected as overkill, since they persist across visits or leak filters into shared links. sessionStorage fits perfectly, partitioned per tab, with a template guard and aria-pressed resync.
In the product manual produced by the KotaPortal generator, the role bar sits right above the content: a row of chips labeled "All", "Admin", "Cashier", "Owner". I picked "Cashier" to see the page from the cashier's point of view, then clicked a sidebar menu to open the "Inventory" page. The active chip was back on "All".
The symptom was consistent. Every sidebar click repeated the same event, without exception.
First guess: localStorage and URL parameters
Since the value had to survive a page change, two candidates came up immediately: write the role to localStorage, or embed it as a URL parameter in every sidebar link. Both do fix the symptom above. Both are also too powerful for the actual problem. And before picking a storage tier, the root cause sits in the shape of the documents themselves.
localStorage makes the role choice persist across visits. A reader opening the manual next week would see the "Owner" view without ever asking for it. URL parameters demand changes to the generator: every sidebar link must carry a query, and a shared link would carry a filter its recipient may not want.
The root cause sits in the manual's own shape. The generator produces 26 separate HTML files [4]. Each page is a standalone document, and moving between pages means a full page load. State stored in the DOM, meaning the active chip, its attributes, and its classes, is thrown away together with the old document.
The state was never lost to a bug. The state simply had nowhere to live.
So the question shifted to the storage tier: where should this state live.
A session per tab, dying with the tab
According to WHATWG, sessionStorage is partitioned by origin and tab 1; its data lives only for the page session, and a new tab or window always starts a new session. The same session can be restored after a reload or session restore, but it never crosses into another tab 2. That behavior is deliberate.
The mapping matches the manual-reading flow exactly. A reader opens the manual in one tab, then flips back and forth between pages while comparing each role's view. The choice must last for that session, and must vanish when the tab closes.
Here lies the difference that often gets swapped: localStorage partitions by origin alone, sessionStorage partitions by origin and tab at once. The second gives per-tab continuity while leaving nothing behind for the next visit.
Template guard and aria-pressed resync
The mechanics are small. When a role is picked, its value is written to the manual-role key in session storage. When a page loads, the value is read back and applied only if the role-tpl-<role> template actually exists on that page. The guard matters: not every page has a template for every role, and applying a role without one would leave empty content behind.
function restoreRole() {
const role = sessionStorage.getItem('manual-role');
if (!role) return; // new visit: leave it on "All"
const tpl = document.getElementById('role-tpl-' + role);
if (!tpl) return; // stay quiet: the page lacks that template
applyRole(role);
syncPressedState(role); // match aria-pressed on the chips
}
The role chips use aria-pressed to mark toggle state 3, and that attribute must be resynced after the role is restored. Without the resync, the content is already filtered while the chips still point to "All". The "All" option returns everything to the default state by removing the manual-role key.
One edge remains, for documentation opened straight from the file system. On opaque origins such as file: or data:, web storage access can throw a SecurityError DOMException 1. Per-browser behavior varies; what the spec settles is the exception itself, not a per-browser table. The pattern above touches storage only on paths that already passed the template guard, so the degradation stays silent.
The decision: use session storage, reject localStorage and URL parameters, and let the role choice die with its tab. If a request ever arrives for the role preference to survive across visits, that is a different product decision with a different storage tier.
Sources
1. MDN, Window: sessionStorage (origin+tab partitioning, page session, survives reloads, SecurityError on file:/data: origins), accessed 2026-11-08.
2. WHATWG HTML Standard #12 Web storage (session data accessible to any page of the same site within one window), accessed 2026-11-08.
3. MDN, ARIA: aria-pressed (tri-state toggle state), accessed 2026-11-08.
4. KotaPortal repo, commit 370e9e5 in the generator APP_JS: the role storage key, the per-role template guard, and the theme twin kept in local storage, internal evidence.