Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/Litext/LTXLabel/Highlight/LTXHighlightRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class LTXHighlightRegion {
self.stringRange = stringRange
}

// Avoid the isolated-deinit runtime crash when synchronous layout releases a region.
// https://github.com/swiftlang/swift/issues/85663
nonisolated deinit {}

func addRect(_ rect: CGRect) {
#if canImport(UIKit)
rects.append(NSValue(cgRect: rect))
Expand Down
30 changes: 30 additions & 0 deletions Tests/MarkdownViewTests/HighlightRegionLifetimeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation
import XCTest
@testable import Litext

@MainActor
final class HighlightRegionLifetimeTests: XCTestCase {
private enum LayoutContext {
@TaskLocal static var value = "outside"
}

// Keep this synchronous: UIKit layout and observation callbacks need not run in a Swift task.
func testSynchronousReleaseInsideTaskLocalScope() {
for _ in 0 ..< 100 {
LayoutContext.$value.withValue("layout") {
autoreleasepool {
var regions = [0: LTXHighlightRegion(
attributes: [NSAttributedString.Key("link"): "https://example.com"],
stringRange: NSRange(location: 0, length: 4)
)]
weak var region: LTXHighlightRegion?
region = regions[0]
regions.removeAll()
XCTAssertNil(region)
}
XCTAssertEqual(LayoutContext.value, "layout")
}
XCTAssertEqual(LayoutContext.value, "outside")
}
}
}
Loading