fix: RichTextView share/copy produces empty content when textView is nil#369
Merged
Merged
Conversation
Author
|
Friendly ping on this PR 👋 Could someone please approve the workflow and review the proposed fix when convenient? I've documented the issue, root cause, and fix details in the PR description. Thanks! |
Owner
|
I appreciate the fix, thank you! 🙇 |
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.
Problem:
When using Pulse inside a UIKit app (via UIHostingController), tapping the share button on a detail page (response body, request body, headers etc.) and selecting "Copy as Text", "Copy as HTML", or "Copy as PDF" copies empty content to the clipboard.
The root cause is in RichTextViewModel.textStorage:
textView is a weak var set by WrappedTextView (a UIViewRepresentable). In UIKit-hosted environments, SwiftUI's view lifecycle differs from a pure SwiftUI app — textView can be nil at the moment the share button closure executes. When that happens, textStorage returns an empty NSTextStorage, resulting in empty clipboard content.
This does not reproduce in pure SwiftUI apps because the view lifecycle keeps textView alive consistently.
Fix:
Fall back to originalText instead of an empty string when textView is nil:
originalText is always populated — it holds the fully rendered attributed string set during initialization. This ensures share/copy always produces the correct content regardless of textView's lifecycle state.