Skip to content
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

Disposal callbacks aren't called when disposing of a TreehouseUi #2248

Open
dellisd opened this issue Aug 14, 2024 · 4 comments
Open

Disposal callbacks aren't called when disposing of a TreehouseUi #2248

dellisd opened this issue Aug 14, 2024 · 4 comments

Comments

@dellisd
Copy link
Collaborator

dellisd commented Aug 14, 2024

The following does not work when a TreehouseUi screen is closed/disposed of on both Android and iOS:

DisposableEffect(Unit) {
  println("Hello")
  
  onDispose {
    // Never called!
    println("World!")
  }
}

A workaround is to use a LaunchedEffect:

LaunchedEffect(Unit) {
  try {
    println("Hello")
    awaitCancellation()
  } finally {
    // This prints fine
    println("World")
  }
}
@dellisd dellisd added the bug label Aug 14, 2024
@JakeWharton
Copy link
Collaborator

If you are tearing down the whole Zipline instance, what's probably happening is that this is running after the binding through which logs are sent is removed.

@dellisd
Copy link
Collaborator Author

dellisd commented Aug 15, 2024

When you say Zipline instance, do you mean for a single screen?

My understanding was that a Zipline instance would survive for the lifetime of the treehouse app, but I'm seeing this issue when tearing down a single screen, e.g. navigating back from a treehouse screen.

@JakeWharton
Copy link
Collaborator

I don't know how it's wired internally, but I would expect each screen to be a Zipline instance, yes. I can look next week.

@swankjesse
Copy link
Collaborator

The Zipline instance spans multiple screens, so I think this is likely a lifecycle step I’ve missed in the Treehouse part of Redwood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants