Fix crash on rotation while drafting a post (#2461)#2473
Open
meet4731 wants to merge 1 commit into
Open
Conversation
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.
Fixes #2461 — the app crashes if you rotate the device while the post composer is open.
Digging into it (and matching the AttributeGraph cycle log pylapp posted on the issue), the crash is a SwiftUI AttributeGraph cycle: when a focused UITextView is in the compose sheet and the interface rotates, the update loop cycles and the watchdog kills the app. The existing device-orientation observer doesn't help here because it only fires after the rotation has already happened, by which point the cycle's formed.
The fix is to host the editor's text view in a small TextViewController (UIViewControllerRepresentable) so it gets a viewWillTransition hook. That fires just before the rotation animation starts, so resigning first responder there drops the keyboard in time to stop the cycle forming in the first place. I've left the orientation observer in as a backstop for the post-rotation case.
One extra change: I had to qualify SwiftSoup.Document in HTMLString.swift — it was hitting an ambiguous type-lookup error building on the current toolchain.
Tested by reproducing the crash (open composer, rotate) and confirming it's gone. Editor sizing and behaviour are unchanged; the only difference is focus now starts on tap rather than automatically.