Closed uniqby closed 4 months ago
Hi @uniqby, this is just how Swift/SwiftUI behaves, for better or worse. The body
of views is marked as @MainActor(unsafe)
, and so everything inside inherits @MainActor
, including refreshable
. But as soon as you move some of the view out to another computed property, it loses the @MainActor
. You can either mark the list
property as @MainActor
, or you can use refreshable { @MainActor in … }
.
Since this is not an issue with the library I am going to convert it to a discussion. Feel to free to continue the conversation over there.
Description
If you add the
.refreshable
modifier to the child property in@ViewBuilder
, attempting to refresh the list triggers a warning that the call was made on a non-main thread:Example:
However, if you place the list directly in the body, everything works as expected without warnings:
Example:
Checklist
main
branch of this package.Expected behavior
No non-main thread warning
Actual behavior
Store.send" was called on a non-main thread with: Test.Action.refresh …
The "Store" class is not thread-safe, and so all interactions with an instance of "Store" (including all of its scopes and derived view stores) must be done on the main thread.
Steps to reproduce
No response
The Composable Architecture version information
1.10.3
Destination operating system
iOS 17.4
Xcode version information
Version 15.3 (15E204a)
Swift Compiler version information