From c2101c16dcaa1411a9500e45bdae52e593e44936 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 19 Apr 2026 15:02:46 +0000 Subject: [PATCH] fix(pdf): avoid closing renderer via delegated read in DisposableEffect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../amethyst/ui/components/pdf/PdfViewerDialog.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/pdf/PdfViewerDialog.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/pdf/PdfViewerDialog.kt index 2062ee7c1..5320f9ec1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/pdf/PdfViewerDialog.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/pdf/PdfViewerDialog.kt @@ -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() } }