pointfreeco / swift-perception

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

Update of tracked @AppStorage properties is not working when the View is wrapped in WithPerceptionTracking #68

Closed thomas-sempf closed 6 months ago

thomas-sempf commented 6 months ago

Description

The bug occurs in Views which are using WithPerceptionTracking and have one or more properties defined via @AppStorage. In this case a view update is not triggered when one of the @AppStorage properties changes. PerceptionBug.zip

Checklist

Expected behavior

View updates are still happening when @AppStorage properties changes

Actual behavior

No update is triggered

Steps to reproduce

  1. Create a view with one or more @AppStorage properties and a @Perceptible view model
  2. Wrap the view in WithPerceptionTracking { ... }
  3. Find out that the updates, which should be propagated by the @AppStorage properties

Perception version information

1.1.6

Destination operating system

iOS 16

Xcode version information

15.3

Swift Compiler version information

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
stephencelis commented 6 months ago

This is sadly a SwiftUI bug in which @AppStorage simply doesn't work in escaping closures. You'll see the same behavior if you swap WithPerceptionTracking out for a GeometryReader. To work around, you can move @AppStorage into its own dedicated subview.

We also recommend filing feedback with Apple if you'd like this bug to be fixed!

Since this is a bug with SwiftUI and not the library, I'm going to convert to a discussion.