SwiftUI View, Open Recent, Revert and Share menus vanish when animating

Graphing Calculator is a SwiftUI macOS FileDocument-based app. There is a slider that can be set to animate on loop, changing a value continuously animating equations. When it is playing the View menu, and Open Recent, Revert and Share submenus flicker and vanish.

The animation is changing a published property of an ObservableObject in the FileDocument.

Any advice on how to go about fixing this in the app?

Is there a way to be notified within the SwiftUI app lifecycle, when the user clicks in the macOS menu bar in order to pause the animation for the duration of the menu selection?

Never mind. After reducing it to a small sample app, I realized I was calling a mutating func on Document in the animation, which explains the behavior.

SwiftUI View, Open Recent, Revert and Share menus vanish when animating
 
 
Q