Repository navigation
fix(ui): canonicalize restored content tabs - #1047
Conversation
joelteply
left a comment
There was a problem hiding this comment.
Quality fix overall — generic RoutingService.resolve replaces brittle hardcoded literal-uniqueId match, canonical-path dedup is the right shape, focus-remap handled. Two specific concerns worth weighing before merge:
(A) catch path is destructive on DB transient (CORRECTNESS). try { resolved = await RoutingService.resolve(...) } catch (error) { console.warn(...) } leaves resolved = null, then the next branch if (!resolved) { dropping stale persisted tab }. Net effect: if RoutingService throws (DB briefly unavailable, IPC socket temporarily down on startup), every persisted tab gets DROPPED and the warn log is the only surviving evidence. Suggest: distinguish 'resolved=null definitively' (entity gone — drop) from 'threw' (couldn't validate — KEEP the tab as-is, log warn). Otherwise a transient startup race silently destroys the user's tab state.
(B) O(N) sequential DB calls (PERF). for (const item of openItems) { await RoutingService.resolve(...) } is sequential. With ~10-20 persisted tabs across rooms+games+wikis the user-perceived restore-startup time grows linearly with tab count, and this runs both at initializeContentTabs AND inside the onStateChange debounce (1000ms throttled but still fires on every userState change). Easy parallelization via Promise.all(openItems.map(...)) — order preservation maintained because dedup happens after, and RoutingService.resolve is per-entity-independent.
(meta) Task #90 in continuum land — '3-way room-set drift, collapse onto ROOM_UNIQUE_IDS as SSOT' remains pending. This PR is the right pragmatic-fix-on-the-read-side, but the underlying drift (multiple sources of truth for what 'general' even means) is still a foundation crack. Worth pinning #90 explicitly in this PR's body or linking issue so it doesn't fall off.
|
LGTM with two evidence-honesty flags worth addressing. Architecture: cleanStrong fix — removes the hardcoded
Concerns1. Resolve-error swallowing (HONESTY). Lines ~537-547 of MainWidget — 2. Async-error fire-and-forget (EVIDENCE). Line 87: Minor
LGTM modulo (1) — that one's a real correctness gap. (2) is a polish/diagnostic concern. Both can be follow-up commits if you want to ship as-is. |
bd851ab to
09483d7
Compare
09483d7 to
f83fb13
Compare
|
Updated again at f83fb13 to cover the remaining diagnostic concern too.\n\nResolved review items:\n- RoutingService.resolve throws now keep the original persisted tab and log the validation failure; only a definitive unresolved/null result drops a stale tab.\n- Restored entity-tab validation now runs via Promise.all, preserving result order while avoiding sequential DB/IPC latency.\n- The onStateChange fire-and-forget sync now attaches a catch handler so async failures surface in the browser console instead of disappearing.\n\nValidation after the fix: npm run build:ts, precommit browser-ping, and pre-push gate all passed. |
Summary
uniqueIdthroughRoutingService, so old UUIDs like the bogus General tab recover to the real room entitycurrentItemIdwhen the focused tab was a dropped stale duplicateWhy
A reseed/schema change can leave
user_states.content_statewith a stale General tab whose old UUID no longer exists. The UI then restores a bogus tab (Loading members..., old messages) next to the real General room. This fixes the persisted-state recovery path instead of requiring localStorage/manual DB cleanup.Validation
npm run build:tschat/general+ staleacademy-training/generalcollapses to one canonical General tab and preserves focus