Xcode14 "Publishing changes from within view updates is not allowed, this will cause undefined behavior."
New "purple warning" in Xcode 14 "Publishing changes from within view updates is not allowed, this will cause undefined behavior.", seemingly related to https://github.com/subconsciousnetwork/ObservableStore/blob/main/Sources/ObservableStore/ObservableStore.swift#L229
self.state = next.state
We must be tripping over some kind of footgun because we're not doing anything too fancy here.
Leads:
- https://developer.apple.com/forums/thread/711899
- https://www.donnywals.com/xcode-14-publishing-changes-from-within-view-updates-is-not-allowed-this-will-cause-undefined-behavior/
- https://stackoverflow.com/questions/73323869/swiftui-publishing-an-environment-change-from-within-view-update
- https://www.hackingwithswift.com/forums/swiftui/xcode-14-publishing-changes-from-within-view-updates-is-not-allowed-this-will-cause-undefined-behavior/16434
From https://www.donnywals.com/xcode-14-publishing-changes-from-within-view-updates-is-not-allowed-this-will-cause-undefined-behavior/
At this point, it seems like this might be a bug in List specifically because changing the list to a VStack or LazyVStack in a ScrollView does not give me the same warning. This tells me that there is nothing fundamentally wrong with the setup above.
I've also seen reports about NavigationView (which is deprecated) triggering this. So it may not have anything to do with us.
Anecdotally confirmed in https://github.com/subconsciousnetwork/subconscious codebase that this seems to be a view-related Apple bug. This seems to trigger when I tap a button in a List in a NavigationView, and not at other times.
Updating to NavigationStack seems to fix this issue. It's not ObservableStore. It's something to do with the deprecated NavigationView.
Video breakdown of warning. "Publishing changes from within view updates is not allowed, this will cause undefined behaviour" https://www.youtube.com/watch?v=3a7tuhVpoTQ