Crash using NSMutableAttributedString with an HMTL document inside a collection view - iOS 18, XCode 16

We're attempting to upgrade to XCode 16 but are encountering a consistent crash when doing so.

The actual exception message comes from the UICollectionView, with this message and stack trace.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view: <Redacted: 0x17831f080; baseClass = UICollectionViewCell; frame = (16 923.667; 408 450); layer = <CALayer: 0x6000004ad680>>; Collection view: <UICollectionView: 0x10ca67000; frame = (0 0; 440 809.667); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600000d41e60>; backgroundColor = <UIDynamicProviderColor: 0x600000285640; provider = <__NSMallocBlock__: 0x600000c7aac0>>; layer = <CALayer: 0x600000322400>; contentOffset: {0, 139.66666666666666}; contentSize: {440, 3247.625}; adjustedContentInset: {0, 0, 34, 0}; layout: <UICollectionViewCompositionalLayout: 0x15a8732a0>; dataSource: <_TtGC5UIKit34UICollectionViewDiffableDataSourceOC8Redacted_: 0x60000000ead0>>'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001804b910c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x0000000180092da8 objc_exception_throw + 72
	2   Foundation                          0x0000000180e67c70 _userInfoForFileAndLine + 0
	3   UIKitCore                           0x00000001852348a4 __43-[UICollectionView _updateVisibleCellsNow:]_block_invoke.445 + 136
	4   UIKitCore                           0x0000000185b2a42c -[_UICollectionViewSubviewManager removeAllDequeuedViewsWithEnumerator:] + 188
	5   UIKitCore                           0x000000018523436c -[UICollectionView _updateVisibleCellsNow:] + 4000
	6   UIKitCore                           0x0000000185234288 -[UICollectionView _updateVisibleCellsNow:] + 3772
	7   UIKitCore                           0x0000000185239174 -[UICollectionView layoutSubviews] + 284
	8   UIKitCore                           0x00000001860a3418 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2404
	9   QuartzCore                          0x000000018b335624 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 432
	10  QuartzCore                          0x000000018b3403f8 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 124
	11  QuartzCore                          0x000000018b272430 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 464
	12  QuartzCore                          0x000000018b2a0c70 _ZN2CA11Transaction6commitEv + 652
	13  QuartzCore                          0x000000018b2a21c4 _ZN2CA11Transaction25flush_as_runloop_observerEb + 68
	14  UIKitCore                           0x0000000185b302fc _UIApplicationFlushCATransaction + 48
	15  UIKitCore                           0x0000000185a60eb4 __setupUpdateSequence_block_invoke_2 + 352
	16  UIKitCore                           0x00000001850a5cec _UIUpdateSequenceRun + 76
	17  UIKitCore                           0x0000000185a60858 schedulerStepScheduledMainSection + 168
	18  UIKitCore                           0x0000000185a5fc90 runloopSourceCallback + 80
	19  CoreFoundation                      0x000000018041d294 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
	20  CoreFoundation                      0x000000018041d1dc __CFRunLoopDoSource0 + 172
	21  CoreFoundation                      0x000000018041c99c __CFRunLoopDoSources0 + 324
	22  CoreFoundation                      0x0000000180416e84 __CFRunLoopRun + 788
	23  CoreFoundation                      0x00000001804166f4 CFRunLoopRunSpecific + 552
	24  UIFoundation                        0x0000000184c5c0c0 -[NSHTMLReader _loadUsingWebKit] + 1416
	25  UIFoundation                        0x0000000184c5cbe8 -[NSHTMLReader attributedString] + 20
	26  UIFoundation                        0x0000000184bdc3c8 _NSReadAttributedStringFromURLOrDataCommon + 2760
	27  UIFoundation                        0x0000000184bd82d4 _NSReadAttributedStringFromURLOrData + 180
	28  UIFoundation                        0x0000000184bd81b8 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 144
	29  Redacted.debug.dylib                0x000000010f53b6d0 $sSo25NSMutableAttributedStringC4data7options18documentAttributesAB10Foundation4DataV_SDySo012NSAttributedC24DocumentReadingOptionKeyaypGSAySo12NSDictionaryCSgGSgtKcfcTO + 204
	30  Redacted.debug.dylib                0x000000010f53a984 $sSo25NSMutableAttributedStringC4data7options18documentAttributesAB10Foundation4DataV_SDySo012NSAttributedC24DocumentReadingOptionKeyaypGSAySo12NSDictionaryCSgGSgtKcfC + 76
	31  Redacted.debug.dylib                0x000000010f53a860 $sSS8RedactedE20htmlAttributedStringSo09NSMutablecD0CSgyF + 572
	32  Redacted.debug.dylib                0x000000010fbddf54 $s8Redacted + 132
	33  Redacted.debug.dylib                0x000000010fbde71c $s8Redacted + 196
	34  Redacted.dylib                0x000000010f75b1d0 $s8Redacted + 544
	35  Redacted.dylib                0x000000010f2ca174 $s8Redacted + 2052
	36  Redacted.debug.dylib                0x000000010e7e6884 $s8Redacted	37  Redacted.debug.dylib                0x000000010e7de9f0 $s8Redacted + 2376
	38  Redacted.debug.dylib                0x000000010f336820 $s8Redacted	39  UIKitCore                           0x0000000184f0c3e8 block_destroy_helper.22 + 18032
	40  UIKitCore                           0x0000000184f109a4 block_destroy_helper + 11080
	41  UIKitCore                           0x0000000184f0e810 block_destroy_helper + 2484
	42  UIKitCore                           0x00000001851aa8f0 -[__UIDiffableDataSource collectionView:cellForItemAtIndexPath:] + 136

libc++abi: terminating due to uncaught exception of type NSException

The collection view cell being dequed contains a string that is created from HTML content with NSMutableAttributedString

This line is where execution stop

            data: data,
            options: [.documentType: NSAttributedString.DocumentType.html],
            documentAttributes: nil
        )

This code has worked fine for years but now inexplicably is crashing. I've seen various similiar posts related to iOS 18 but none with a resolution

Crash using NSMutableAttributedString with an HMTL document inside a collection view - iOS 18, XCode 16
 
 
Q