fix(pdf): avoid closing renderer via delegated read in DisposableEffect
DisposableEffect(handleState) captured handleState as a property delegate, so onDispose read the *current* delegated value at dispose time. When the async load transitioned handleState from null to the new handle, the previous DisposableEffect(null) was forgotten and its onDispose fired — reading the freshly-created handle via the delegate and closing it immediately. That left the dialog stuck on the loading spinner (page renders bailed out due to the closed flag) and double- closed the renderer on dismiss. Capture the handle as a local val before DisposableEffect so the lambda closes the specific handle that was current at effect creation.
This commit is contained in:
+8
-2
@@ -161,9 +161,15 @@ private fun PdfViewerContent(
|
||||
}
|
||||
}
|
||||
|
||||
DisposableEffect(handleState) {
|
||||
// Capture the handle as a local val so the onDispose lambda closes *this* handle,
|
||||
// not whatever the delegated property reads at dispose time. Without this, the
|
||||
// DisposableEffect keyed on handleState runs its onDispose when handleState
|
||||
// transitions from null -> handle, and `handleState?.close()` reads the new handle
|
||||
// and closes it right after it was created.
|
||||
val handleForDispose = handleState
|
||||
DisposableEffect(handleForDispose) {
|
||||
onDispose {
|
||||
handleState?.close()
|
||||
handleForDispose?.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user