Interesting to know about the mitigation options and that ViewBuilder has similar concerns. It makes me curious as to why VStack works for helping the evaluation stop short when a self defined WrapperView might not (I gave this a shot).
A potential improvement on your suggested mitigation comes to mind and would be a more robust solution against misuse or failing to mitigate.
Rather than having the protocol return an AnyView we could introduce a custom WrappedAnyView and return it.
struct WrappedAnyView: View {
let wrapped: AnyView
init(_ wrapped: AnyView) {
Get Abraham Hunt’s stories in your inbox
Join Medium for free to get updates from this writer.
self.wrapped = wrapped
}
var body: some View {
VStack { wrapped }
}
}
Doing something like this would better serve to centralize and standardize any code base that might seek to use this type of mitigation.




