Skip to content

fix(ui): hold the navigation controller weakly in menu pages - #1392

Merged
ross-dash merged 2 commits into
developfrom
fix/weak-nav-controller-refs
Nov 13, 2026
Merged

ross-dash merged 2 commits into
developfrom
fix/weak-nav-controller-refs

Conversation

@ross-dash

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1220, as promised in its review: SwiftUI pages pushed onto a UIKit UINavigationController kept a strong reference to that controller while their own hosting controller sat in its stack. A normal pop breaks the cycle, but a stack dropped or rebuilt with the page still on it (e.g. MainTabbarController.configureControllers() replacing a tab's navigation controller) was never released.

Same pattern as #1220: weak var vc: UINavigationController? with vc?. call sites, and guard let vc where the controller is handed to an API that needs a non-optional one.

Pages changed

  • Settings, Security, Tools, Governance, Explore menu, Connections
  • Identities (list, detail, public keys), Wallets, Wallet accounts, Wallet account detail
  • Sync info menu, Shielded / DashPay / SPV / Platform sync status
  • MainMenuScreen — it is not the stack's owner but the content of its root view controller, so it formed the same cycle
  • KeysOverviewContentView (Masternode keys overview)

UsernameMarketplaceScreen and DevnetSettingsHostingViewController already stored the controller weakly; their initializers now just accept an optional.

Testing

  • dashpay scheme builds for the simulator
  • scripts/a11y_audit.py --check passes
  • No behaviour change expected: every page still navigates through the same stack it was pushed onto

🤖 Generated with Claude Code

SwiftUI pages pushed onto a UIKit navigation controller kept a strong
reference to that controller while their own hosting controller sat in
its stack. A normal pop breaks that cycle, but a stack that is dropped
or rebuilt with the page still on it (for example when
MainTabbarController.configureControllers() replaces a tab's navigation
controller) was never released.

Same fix as the pages converted in #1220: `weak var vc:
UINavigationController?` with optional-chained call sites, and a
`guard let vc` where the controller is handed to an API that needs a
non-optional one. Covers the Settings, Security, Tools, Governance,
Explore, Connections, Identities (3 pages), Wallets, Wallet accounts,
Wallet account detail, Sync info pages, the main menu (root of its
stack) and the Masternode keys overview. UsernameMarketplaceScreen and
DevnetSettingsHostingViewController already stored it weakly; their
initializers now take an optional.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6e3e8d3a-65b2-4f54-a08e-8835ccccf962
Commits

Reviewing files that changed from the base of the PR and between 0c6bb7a and b5fdaea.

Files selected for processing: 19

  • DashWallet/Sources/UI/DashConnect/ConnectionsScreen.swift
  • DashWallet/Sources/UI/Explore Dash/ExploreMenuScreen.swift
  • DashWallet/Sources/UI/Explore Dash/UsernameMarketplaceScreen.swift
  • DashWallet/Sources/UI/Menu/Governance/GovernanceMenuScreen.swift
  • DashWallet/Sources/UI/Menu/Main/MainMenuViewController.swift
  • DashWallet/Sources/UI/Menu/Security/SecurityMenuScreen.swift
  • DashWallet/Sources/UI/Menu/Security/Wallets/IdentitiesScreen.swift
  • DashWallet/Sources/UI/Menu/Security/Wallets/WalletAccountDetailScreen.swift
  • DashWallet/Sources/UI/Menu/Security/Wallets/WalletAccountsScreen.swift
  • DashWallet/Sources/UI/Menu/Security/Wallets/WalletsScreen.swift
  • DashWallet/Sources/UI/Menu/Settings/DevnetSettingsScreen.swift
  • DashWallet/Sources/UI/Menu/Settings/SettingsScreen.swift
  • DashWallet/Sources/UI/Menu/SyncInfo/DashPaySyncInfoScreen.swift
  • DashWallet/Sources/UI/Menu/SyncInfo/PlatformSyncStatusScreen.swift
  • DashWallet/Sources/UI/Menu/SyncInfo/ShieldedSyncInfoScreen.swift
  • DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift
  • DashWallet/Sources/UI/Menu/SyncInfo/SyncInfoMenuScreen.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/KeysOverviewView.swift
  • DashWallet/Sources/UI/Menu/Tools/ToolsMenuScreen.swift
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thepastaclaw

thepastaclaw commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit b5fdaea) · triage: low

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

The weak navigation references are appropriate, but two stored closures still create retain cycles in the menu lifecycle this PR aims to fix. Both issues are confirmed at d1d16e9. Exact-head simulator tests and supporting CI checks passed; this verification was static and did not establish runtime deallocation.

🔴 2 blocking

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a cross-cutting UI ownership change across 19 files that requires checking weak-reference lifetimes and optional navigation paths, but does not change a critical surface.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `DashWallet/Sources/UI/Menu/Security/SecurityMenuScreen.swift`:
- [BLOCKING] DashWallet/Sources/UI/Menu/Security/SecurityMenuScreen.swift:37-39: Capture Security's initializer navigation parameter weakly
  The stored onHide closure captures the initializer parameter vc strongly, not the weak self.vc property. SecurityMenuScreen retains DelegateInternal, which retains onHide, leaving the cycle navigation controller → hosting controller → SecurityMenuScreen → DelegateInternal → onHide → navigation controller. Replacing or dropping a stack containing Security therefore still retains that stack despite the property change. Add [weak vc], matching WalletsScreen's reset delegate, and add a deallocation regression test that drops the containing stack.

In `DashWallet/Sources/UI/Menu/Main/MainMenuViewController.swift`:
- [BLOCKING] DashWallet/Sources/UI/Menu/Main/MainMenuViewController.swift:150-152: Also break the root menu's support-callback retain cycle
  Weakening vc removes the direct navigation-controller reference, but MainMenuScreen still retains onContactSupport. setupSwiftUIView() constructs that callback with a strong self capture in both compilation branches (lines 109–110 and 117–118), creating the independent cycle MainMenuViewController → hostingController → MainMenuScreen → onContactSupport → MainMenuViewController. Consequently, a loaded More root and its hosted models remain alive after configureControllers() replaces the tab's stack, even if the navigation controller itself releases. This is part of the root-menu teardown explicitly covered by this PR. Capture [weak self] and call self?.presentSupportEmailController() in both branches; verify that the loaded root and its hosting controller deallocate when the stack is dropped.

- SecurityMenuScreen's onHide captured the init parameter vc strongly,
  not the weak property; it now captures it weakly.
- MainMenuViewController's onContactSupport captured self strongly
  while the screen storing it is hosted by self; it now captures
  [weak self].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

The complete base-to-head diff correctly weakens the menu pages' navigation-controller back-references and updates their call sites without introducing a new ownership or navigation defect. Both prior blocking findings are fixed at this head: the root support callback captures its owner weakly in both compilation branches, and Security's initializer callback captures its navigation parameter weakly. Accessibility, test-membership, workflow-lint, and PR-title checks passed; simulator tests remain queued.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, well-contained UI ownership fix that changes navigation-controller references from strong to weak without altering business logic or any critical surface.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 81% left, weekly 62% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@romchornyi-pitcrew romchornyi-pitcrew left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: ready to merge

No blockers or majors. Reviewed at b5fdaea. Static read only, nothing built.

Level Verdict
1 · Idea ✅ A real cycle: each page's hosting controller sits in the stack that its root view held strongly. A normal pop breaks it, but a stack dropped with the page on it leaked
2 · Architecture ✅ The same weak var vc pattern as #1220
3 · Completeness ✅ A search for stored UINavigationController properties at this head finds no strong one left in DashWallet/
4 · Code ✅ Clean

Checked

  • Every page receives the stack it is pushed onto, and that stack has a strong owner elsewhere. A tab's BaseNavigationController is held by MainTabbarController, and a modal one by its presenter. So vc is non-nil whenever the page is on screen, and guard let vc else { return } / vc?. can only no-op once the stack is already gone. Call sites checked:
  • The two pastaclaw blockers are fixed at this head.
  • No other captures of the initializer parameter. None of the changed files has a closure that still captures the initializer's vc parameter strongly. UsernameMarketplaceScreen already used [weak vc].
  • The UI-test fixture keeps its stack alive. It returns its plain UINavigationController as the window root, so the weak vc stays alive there.

Recommendations (non-blocking)

  1. No deallocation test. The PR keeps to a static fix, as #1220 did. A unit test that replaces a tab's stack, or drops a UINavigationController holding e.g. IdentitiesScreen, and asserts both deallocate would stop the pattern from coming back on the next page that copies the old let vc.
  2. Preview vc is nil. The ConnectionsScreen preview passes UINavigationController() straight into a weak property (L256), so the preview's vc is nil from the start. That is harmless for a preview, but vc: nil says it honestly.
  3. Merge order with #1394. The two PRs conflict in 9 files (MainMenuViewController, SettingsScreen, IdentitiesScreen, ToolsMenuScreen, …), because #1394 deletes the hidesBottomBarWhenPushed lines next to the call sites this PR rewrites. The resolution is mechanical (keep vc?., drop the flag), but whichever merges second needs a rebase.

🤖 Reviewed with Claude Code

@ross-dash
ross-dash merged commit 2a7bf3a into develop Nov 13, 2026
7 checks passed
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.

3 participants