I have a two alternative "content views" (depending on sizeClasses) that are using swiftUI feature .onPreferenceChange to update different sizes of the content.
The preferences are updated by some view modifiers.
Sometimes when rotating the device both views are on screen the same time during the transition. I suspect that this is causing my problem:
I get trapped by the assertion for isSending in the Stores send function.
However,
if I look at the stack trace I can see another call to send (72 frames down) that comes from a viewStore binding (in a different view of the app that also reacts to device rotation).
They are both on the main thread and they are not recursive. How come they are both active the same time?
Interestingly, the problem disappears when I replace the viewStore.binding with a manually contracted Binding(get:set) and do the viewStore.send(Action) in the set closure.
The .onCommit action will fire an Effect from the environment that dismisses the keyboard, which in turn will cause the textfield to fire it's onEditingChanged handler and BAM; the dreaded ** The store was sent an action recursively.** assertion.. I've already tried to dodge this problem before in another scenario with the condition in the handler but that doesn't help now.
I have invited you to a private repo with the code.
I've tried to make it to the bare minimal to invoke the strange behaviour but I'm not sure if I'm ready to put it in a public repo yet.