pointfreeco / swift-perception

Observable tools, backported.
MIT License
574 stars 43 forks source link

Runtime Warning: Geometry Proxy - Nested Closure #87

Closed ollieatkinson closed 5 months ago

ollieatkinson commented 5 months ago

Description

When updating state from a nested closure of a GeometryReader the PerceptionRegistrar perceptionCheck incorrectly labels it as isGeometryTrailingClosure.

This was originally observed as I had a gesture onChanged inside of a GeometryProxy.

Checklist

Expected behavior

No runtime warning

Actual behavior

Runtime warning

Perceptible state was accessed but is not being tracked. Track changes to state by wrapping your view in a 'WithPerceptionTracking' view.

Steps to reproduce

Failing Test

@MainActor
func testGeometryReader_GeometryProxyNestedClosure_ImproperPerceptionTracking() async throws {
  struct FeatureView: View {
    let model = Model()
    var body: some View {
      WithPerceptionTracking {
        content
      }
    }
    var content: some View {
      GeometryReader { _ in
        WithPerceptionTracking {
          ZStack {}
            .task { @MainActor in _ = model.count }
        }
      }
    }
  }
  self.render(FeatureView())
  try await Task.sleep(for: .milliseconds(100))
}

Output of demangled symbol

"(1) suspend resume partial function for closure #2 @Swift.MainActor @Sendable () async -> () in closure #1 () -> <<opaque return type of (extension in SwiftUI):SwiftUI.View.task(priority: Swift.TaskPriority, _: @Sendable () async -> ()) -> some>>.0 in closure #1 (SwiftUI.GeometryProxy) -> Perception.WithPerceptionTracking<<<opaque return type of (extension in SwiftUI):SwiftUI.View.task(priority: Swift.TaskPriority, _: @Sendable () async -> ()) -> some>>.0> in content.getter : some in FeatureView #1 in PerceptionTests.RuntimeWarningTests.testGeometryReader_GestureChanged_ImproperPerceptionTracking() async throws -> ()"

Perception version information

1.2.4

Destination operating system

iOS 17

Xcode version information

Xcode 15.1

Swift Compiler version information

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0