Repository navigation
Fix empty content state after closing last tab - #1054
Conversation
joelteply
left a comment
There was a problem hiding this comment.
Architecturally sound — making PageState nullable is the right contract for "no active content". TS type change PageState → PageState | null enforces null-handling on new subscribers; that's the right teeth.
Audit found two existing PageState subscribers NOT explicitly updated by this PR; both happen to handle null safely:
src/system/state/PositronicRAGContext.ts:pageState.subscribe(debounced)— debounced callback only signals 'state changed, re-fetch' without dereferencingstate. Null-safe by design.src/widgets/chat/chat-widget/ChatWidget.ts(via BaseWidget.subscribeToPageState): callback usesnewState?.contentType === 'chat'andnewState?.entityIdthroughout. Optional-chaining meansnull→ undefined → falsy →setActiveContent(false, ...)correctly hides chat. Null-safe by accident, but works today.
Worth a one-line PR-body note that these were audited so future maintainers don't grep and worry. Otherwise no concerns; ship it.
Tiny nit: private clearUrl() does window.history.pushState({path: '/'}, '', '/') — could just be this.updateUrl('/') if updateUrl handles / (saves a private method). Pure cleanup, not blocking.
|
LGTM as architecture — clean state-contract change, not a string patch. What it actually does
Verified subscriber null-safety (the breaking-contract risk)
No subscriber will crash on null. Type system enforces it for any new ones. Architecture observations
Concerns (non-blocking)
LGTM. Ship + test in browser to confirm cross-component contract holds (this is the bit that browser-reload validation actually exercises that the protocol-check tests don't). |
fcfa4a0 to
14537c9
Compare
Summary
Makes the zero-open-tabs state explicit instead of leaving the last rendered widget visible.
This is a state-contract fix, not a special-case General-room patch:
PageStateServicenow notifies subscribers when page state is cleared (PageState | null).ContentService.close()clears page state and resets the URL to/when the active last tab closes.MainWidgetresponds to cleared page state by hiding cached content widgets and clearing right-panel config.RoomListWidgetclears its active room highlight when there is no active page state.subscribe -> clear -> null callbackcontract.Why
Joel observed that after closing both General tabs, the center widget could still look like chat/General. That points to stale active view state after the last tab closes, separate from PR #1047's persisted duplicate tab cleanup.
The desired invariant is: content state owns whether anything is open; page state mirrors an active item only; widgets must not fabricate General when no content item is active.
Subscriber audit
All PageState subscribers were checked after changing the listener type to
PageState | null:MainWidget: explicitly clears the active content view onnull.RoomListWidget: explicitly clears active room highlight onnull.ChatWidget: already null-safe via optional chaining onnewState?.contentType/newState?.entityId.PositronicRAGContext: subscribes through a debounced callback and reads state later throughpageState.getContent(), which is already nullable.Validation
npx vitest run tests/unit/PageStateService.test.tspassed (2 tests)npm run build:tspassedtests/precommit/browser-ping.test.tsNote: this package has Vitest-style tests but does not declare
vitestinsrc/package.json;npxfetched Vitest for the focused local run. That dependency hygiene issue should be handled separately, not hidden in this UI-state PR.Manual acceptance
/./chat/general: exactly one canonical General tab opens, using the seeded room identity from routing.