Bind delayed instruction hide to SwiftUI view lifecycle#4382
Merged
bgoncal merged 1 commit intohome-assistant:mainfrom Feb 22, 2026
Merged
Bind delayed instruction hide to SwiftUI view lifecycle#4382bgoncal merged 1 commit intohome-assistant:mainfrom
bgoncal merged 1 commit intohome-assistant:mainfrom
Conversation
78282b8 to
d4c2b1f
Compare
Contributor
There was a problem hiding this comment.
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
.onAppearwith.taskmodifier for lifecycle-bound task management - Added early return guard to check if instructions are already hidden
- Wrapped state mutation in
MainActor.runfor explicit main thread execution
Comments suppressed due to low confidence (1)
Sources/App/Cameras/CameraList/CamerasRoomView.swift:87
- The
MainActor.runwrapper is unnecessary here. SwiftUI@Stateproperties are already@MainActorisolated, and updates to them from within a.taskmodifier are automatically executed on the main actor. You can directly updateshowInstructionswithin thewithAnimationblock.
await MainActor.run {
withAnimation {
showInstructions = false
}
}
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
bgoncal
approved these changes
Feb 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.