fix(pdfx): guard PdfViewPinch._needReLayout against setState after dispose - #648
Open
Yusuke-Shimamura wants to merge 1 commit into
Open
fix(pdfx): guard PdfViewPinch._needReLayout against setState after dispose#648Yusuke-Shimamura wants to merge 1 commit into
Yusuke-Shimamura wants to merge 1 commit into
Conversation
…spose _needReLayout schedules setState via Future.delayed(Duration.zero) without checking `mounted`. If the viewer is unmounted in the same frame that scheduled the relayout, the callback runs on a disposed State: in debug this is "setState() called after dispose()", in release the assert is stripped and it surfaces as "Null check operator used on a null value" from State.setState. Check `mounted` like the other delayed callbacks in this file already do. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
_PdfViewPinchState._needReLayoutschedulessetStatethroughFuture.delayed(Duration.zero, ...)without checkingmounted. When the viewer is unmounted in the same frame that scheduled the relayout (for example, the page hostingPdfViewPinchis popped while ajumpToPage/animateToPagetick or a relayout changed the set of visible pages), the callback lands on a disposedState.setState() called after dispose().Null check operator used on a null valuethrown fromState.setState(_element!.markNeedsBuild()), which ends up in the app's zone error handler.Observed in production on Flutter web with pdfx 2.9.2. Decoded stack:
Fix
Check
mountedinside the delayed callback, matching the other delayed callbacks in this file (the loading-state listener and the first-attach callback in_reLayoutalready do this).Notes
_updateRealSizeOverlay(#598) is a related but different path (async work continuing after dispose) and is not touched here.🤖 Generated with Claude Code