Skip to content

Bind delayed instruction hide to SwiftUI view lifecycle#4382

Merged
bgoncal merged 1 commit intohome-assistant:mainfrom
llkenny:fix/lifecycle-task
Feb 22, 2026
Merged

Bind delayed instruction hide to SwiftUI view lifecycle#4382
bgoncal merged 1 commit intohome-assistant:mainfrom
llkenny:fix/lifecycle-task

Conversation

@llkenny
Copy link
Copy Markdown
Contributor

@llkenny llkenny commented Feb 22, 2026

Summary

Problem
CamerasRoomView hides instructions with a delayed Task started from onAppear. The task is not lifecycle-bound and can still mutate showInstructions after the view disappears.

Change
Move the delayed hide logic to SwiftUI .task so it is automatically cancelled when the view leaves the hierarchy. Keep behavior unchanged (instructions still hide after ~3s).

Screenshots

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

Verification
Built the app target locally. Relying on CI (GitHub Actions) to run tests/build.

Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @llkenny

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@llkenny llkenny marked this pull request as ready for review February 22, 2026 16:02
Copilot AI review requested due to automatic review settings February 22, 2026 16:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a lifecycle bug in CamerasRoomView where a delayed task to hide UI instructions could continue to mutate state after the view disappears. The change migrates from .onAppear with a manual Task to the SwiftUI .task modifier, which automatically cancels the task when the view leaves the hierarchy.

Changes:

  • Replaced .onAppear with .task modifier for lifecycle-bound task management
  • Added early return guard to check if instructions are already hidden
  • Wrapped state mutation in MainActor.run for explicit main thread execution
Comments suppressed due to low confidence (1)

Sources/App/Cameras/CameraList/CamerasRoomView.swift:87

  • The MainActor.run wrapper is unnecessary here. SwiftUI @State properties are already @MainActor isolated, and updates to them from within a .task modifier are automatically executed on the main actor. You can directly update showInstructions within the withAnimation block.
                await MainActor.run {
                    withAnimation {
                        showInstructions = false
                    }
                }

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@5c85ffc). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4382   +/-   ##
=======================================
  Coverage        ?   42.97%           
=======================================
  Files           ?      262           
  Lines           ?    15182           
  Branches        ?        0           
=======================================
  Hits            ?     6524           
  Misses          ?     8658           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bgoncal bgoncal dismissed home-assistant[bot]’s stale review February 22, 2026 20:37

Cla is signed already

@bgoncal bgoncal merged commit c05233b into home-assistant:main Feb 22, 2026
12 of 13 checks passed
@llkenny llkenny deleted the fix/lifecycle-task branch February 23, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants