Fix publishing changes during view updates warning

Defer state mutations in .onReceive handlers to next run loop
by wrapping them in Task { @MainActor in ... }
This commit is contained in:
世界
2026-01-05 14:15:53 +08:00
parent e68af19112
commit af9cfd0f59
3 changed files with 31 additions and 25 deletions
@@ -155,19 +155,23 @@ import SwiftUI
}
#if os(iOS) || os(tvOS)
.onReceive(environments.commandClient.$groups) { _ in
updateButtonVisibility()
#if os(iOS)
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
coordinator.selection = .overview
}
#endif
Task { @MainActor in
updateButtonVisibility()
#if os(iOS)
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
coordinator.selection = .overview
}
#endif
}
}.onReceive(profile.$status) { _ in
updateButtonVisibility()
#if os(iOS)
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
coordinator.selection = .overview
}
#endif
Task { @MainActor in
updateButtonVisibility()
#if os(iOS)
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
coordinator.selection = .overview
}
#endif
}
}.onAppear {
updateButtonVisibility()
}