Skip to content

Commit 041b171

Browse files
Resolve crash within NavigationSplitView in v2.3.4 (#102)
Hey! Per your recommendation, we (Bitrig) updated `STTextView` to v2.3.4 today. Unfortunately, this caused our app to crash on launch when using `STTextView` within a `SwiftUI.NavigationSplitView`. Sample code: ```swift struct ContentView: View { var body: some View { NavigationSplitView { Spacer() } detail: { TextView( text: .constant(.init("Wow")) ) .font(.system(size: 12, weight: .regular, design: .monospaced)) } } } ``` <img width="703" height="212" alt="Screenshot 2026-01-14 at 3 29 16 PM" src="https://github.com/user-attachments/assets/b7ce1e07-ec8d-4b8c-bd12-15a584223004" /> I investigated the crash and believe it was caused by an invalidation loop from `NavigationSplitView` while `STTextView` is resizing during layout. I found that implementing `sizeThatFits` to accept SwiftUI's size proposal resolves the crash. We have already made this change in our internal source editor package. I'm making this PR to share the fix with other users as well in case it's helpful. Thank you!
1 parent 986617e commit 041b171

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/STTextViewSwiftUIAppKit/TextView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ private struct TextViewRepresentable: NSViewRepresentable {
121121

122122
return scrollView
123123
}
124+
125+
func sizeThatFits(_ proposal: ProposedViewSize, nsView: NSScrollView, context: Context) -> CGSize? {
126+
let width = proposal.width ?? nsView.frame.size.width
127+
let height = proposal.height ?? nsView.frame.size.height
128+
return CGSize(width: width, height: height)
129+
}
124130

125131
func updateNSView(_ scrollView: NSScrollView, context: Context) {
126132
let textView = scrollView.documentView as! STTextView

0 commit comments

Comments
 (0)