Skip to content

fix(app): dispose the workspace on navigate-home - #284

Merged
DeepDiver1975 merged 1 commit into
mainfrom
fix/review-workspace-dispose
Sep 11, 2026
Merged

DeepDiver1975 merged 1 commit into
mainfrom
fix/review-workspace-dispose

Conversation

@DeepDiver1975

Copy link
Copy Markdown
Contributor

Problem

IncidentWorkspaceViewModel was not IDisposable. Its child tab view-models were only disposed when BuildChildren replaced them; navigating home from a workspace (both the GoHomeRequested path and the GoHome command) simply dropped the workspace. The Scba, Tasks and Reminder children keep ITicker subscriptions and session.Changed handlers, and DispatcherTimerTicker holds strong references, so every abandoned workspace kept ticking once per second forever. ScbaViewModel.OnTick could still append journal entries and play alarms for an incident the user had already left. The four RemoteIncidentSession event subscriptions were never removed either.

Fix

  • IncidentWorkspaceViewModel implements IDisposable: one idempotent teardown that disposes every child and unsubscribes the remote-session events.
  • MainWindowViewModel disposes the outgoing workspace on both navigation paths, after the existing LeaveAsync (remote session teardown).
  • Tests: after navigating home the ticker double has zero subscribers and session.Changed no longer reaches the old workspace's children.

Found during a code review of main; part of a series of review follow-up PRs.

Test plan

  • dotnet test LageBuch.Desktop.slnf green
  • New tests shown failing before the fix

🤖 Generated with Claude Code

https://claude.ai/code/session_01PXhXSh2pae9WnaACYUUe3V

IncidentWorkspaceViewModel was never IDisposable, so navigating home only
ever disposed its child tab view models inside BuildChildren (on a
rebuild) -- never on final teardown. The last generation of children,
and the workspace's own ticker subscriptions carried by Scba/Tasks/
Reminder, outlived the navigation: an abandoned workspace kept ticking
once a second and could still append to its journal or play alarms for
an incident nobody could see anymore. A joined client additionally
leaked its four RemoteIncidentSession lifecycle subscriptions (Changed,
Disconnected, Reconnected, Ended) with no matching unsubscribe.

Make IncidentWorkspaceViewModel : IDisposable. Dispose() is now the
single, idempotent teardown point: it unsubscribes the four remote
events and disposes every current child via a DisposeChildren() helper
shared with BuildChildren, so a workspace rebuilt several times still
only disposes its current children once.

MainWindowViewModel disposes the outgoing workspace via a
OnCurrentViewChanged(object?, object?) hook on CurrentView, so it fires
uniformly for every navigate-away path (GoHome, GoHomeRequested, and
beyond) without duplicating a Dispose() call at each call site. GoHome
now awaits the outgoing workspace's LeaveAsync() (tearing down a joined
client's remote session) before switching CurrentView, matching
ShowWorkspace's existing GoHomeRequested lambda.

Ownership of a freshly constructed IncidentWorkspaceViewModel transfers
from HomeViewModel to whoever handles WorkspaceOpened, which is now
what disposes it -- suppress the two resulting CA2000 findings with a
justification.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PXhXSh2pae9WnaACYUUe3V
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975
DeepDiver1975 force-pushed the fix/review-workspace-dispose branch from 4ab8d7e to 1a5923e Compare September 11, 2026 09:20
@DeepDiver1975
DeepDiver1975 merged commit a3a3eaf into main Sep 11, 2026
3 checks passed
@DeepDiver1975
DeepDiver1975 deleted the fix/review-workspace-dispose branch September 11, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant