Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary "observe" warning #3005

Closed
2 of 3 tasks
nmalevich opened this issue Apr 23, 2024 · 1 comment
Closed
2 of 3 tasks

Unnecessary "observe" warning #3005

nmalevich opened this issue Apr 23, 2024 · 1 comment

Comments

@nmalevich
Copy link

Description

Warning "An "observe" was called from another "observe" closure, which can lead to over-observation and unintended side effects." was added in version 1.9.3 and become at unnecessary cases
I attach example project where you can see that bug
BadObserveExample.zip

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

Warning doesn't appear

Actual behavior

Warning appears

Steps to reproduce

Just run app and wait. Screens will navigate by themselves

The Composable Architecture version information

1.9.3

Destination operating system

iOS 17.4.1

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)
@nmalevich nmalevich added the bug Something isn't working due to a bug in the library. label Apr 23, 2024
@stephencelis
Copy link
Member

@nmalevich We recently added this runtime warning because nested observes can have unintended consequences. In this case, a viewDidLoad is evaluated in the same stack as the presenting view controller's observe, which means all child state evaluated in the child controller's observe will be observed by the parent.

To work around the problem, you can move observe into viewWillAppear instead, and manage the lifetime of the observation token, or you can dispatch the observation a tick in viewDidLoad:

DispatchQueue.main.async {
  observe { [weak self] in
    …
  }
}

We're still deciding if this warning is too heavy-handed, but we don't consider it a bug at the moment. Because of this I'm going to convert this to a discussion.

@stephencelis stephencelis removed the bug Something isn't working due to a bug in the library. label Apr 23, 2024
@pointfreeco pointfreeco locked and limited conversation to collaborators Apr 23, 2024
@stephencelis stephencelis converted this issue into discussion #3006 Apr 23, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants