ObservableStore icon indicating copy to clipboard operation
ObservableStore copied to clipboard

Xcode14 "Publishing changes from within view updates is not allowed, this will cause undefined behavior."

Open gordonbrander opened this issue 3 years ago • 2 comments

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

gordonbrander avatar Sep 17 '22 14:09 gordonbrander

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.

gordonbrander avatar Sep 17 '22 14:09 gordonbrander

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.

gordonbrander avatar Sep 19 '22 15:09 gordonbrander

Updating to NavigationStack seems to fix this issue. It's not ObservableStore. It's something to do with the deprecated NavigationView.

gordonbrander avatar Jan 20 '23 16:01 gordonbrander

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

gordonbrander avatar Jan 22 '23 21:01 gordonbrander