{"success":true,"name":"the-same-web-app-in-two-tabs-is-two-copies-plan-how-they-sha","description":"Building a web app and users will open it in several tabs","category":"ai-brimind","path":"ai-brimind/the-same-web-app-in-two-tabs-is-two-copies-plan-how-they-sha/SKILL.md","file":"SKILL.md","content":"---\nname: the-same-web-app-in-two-tabs-is-two-copies-plan-how-they-sha\ndescription: \"Building a web app and users will open it in several tabs\"\n---\n\n# The Same Web App in Two Tabs Is Two Copies: Plan How They Share Auth and State\n\n## When to use\nA web app keeps session, auth, or important state in the browser, and the same user can have it open in multiple tabs or windows at once.\n\n## Example request\nUser logs out in tab A → tab B still shows their account and keeps firing authorized requests; auth changes need to broadcast across tabs. — Both tabs edit the same record from memory → last save silently overwrites the first; each tab holds its own stale copy of the world. — Token refresh runs in every tab simultaneously → refresh calls race and invalidate each other; one tab must win (a lock or shared coordination is the mechanism). — Draft autosaved from two tabs into one storage key → they overwrite each other's work in turns; per-tab or merge-aware storage is the deliberate choice.\n\n## Instructions\nAct as a coordinator who assumes every user runs the app twice at once, because they do. When browser-held state matters: 1) Inventory what state lives in the browser and classify each piece: must be identical across tabs (auth/session), per-tab by nature (navigation, wizard progress), or shared-but-conflictable (drafts, edits) — the class decides the handling, and unclassified state defaults to whichever failure hurts most. 2) For auth: login and logout must propagate — the browser has built-in cross-tab signals (storage events, broadcast channels); use the platform mechanism instead of hoping tabs stay in sync. 3) For anything two tabs can both write — a shared storage key, a token refresh, a draft — name the race explicitly and pick the resolution: one designated winner, a lock, or merge; 'probably won't happen' is not a resolution. 4) Remember background tabs are throttled and can hold very stale data; a tab returning to focus should re-check what it believes before acting on it. 5) Test the boring reality: open two tabs, log out in one, edit in both, and watch — this five-minute test finds what reasoning misses. If you can't tell which states are shared, trace where each is read and written first. Only call multi-tab handled once the two-tab test confirms no silent overwrite or ghost session, and explain what mechanism keeps each state class correct rather than assuming one tab per user.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #972\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}