Crash using .searchable bound to viewModel and sidebar placement on macOS

Originator:damian
Number:rdar://FB13541783 Date Originated:14 Jan 2024
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:macOS 14.2.1 (23C71), xCode 15.2 (15C500b)
 
Consider this complete SwiftUI macOS app

```swiftui
//
//  TestSearchStringInViewModelApp.swift
//  TestSearchStringInViewModel
//
//  Created by Damian Mehers on 2024-01-15.
//

import SwiftUI

@main
struct TestSearchStringInViewModelApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    // using @Bindable or plain "var" with a Bindable<ViewModel> object in the code does same thing
    @State var viewModel = ViewModel()
    var body: some View {
        NavigationSplitView {
            VStack {
                List(1..<5) { n in
                    Text("\(n)")
                }
                .listStyle(SidebarListStyle())
                // Works if not sidebar or @State searchString
                .searchable(text: $viewModel.searchString, placement: .sidebar)
            }
        } detail: {
            Text("Some detail")
        }
    }
}

@Observable final class ViewModel {
    var searchString = ""
}
```

When you run it, when you tap “a” into the searchbar two “a”s appear, and when they are both deleted you get a crash:

```
An uncaught exception was raised
*** -[NSBigMutableString substringWithRange:]: Range {0, 1} out of bounds; string length 0
(
	0   CoreFoundation                      0x00000001820d0570 __exceptionPreprocess + 176
	1   libobjc.A.dylib                     0x0000000181bc1eb4 objc_exception_throw + 60
	2   Foundation                          0x0000000183131930 -[NSString _newSubstringWithRange:zone:] + 0
	3   AppKit                              0x00000001859e6f28 -[NSTextStorage(NSUndo) _undoRedoAttributedSubstringFromRange:] + 140
	4   AppKit                              0x00000001859e6e04 -[NSUndoTyping initWithAffectedRange:textStorage:undoManager:replacementRange:] + 132
	5   AppKit                              0x00000001859e6c6c -[NSTextViewSharedData coalesceInTextView:affectedRange:replacementRange:] + 308
	6   AppKit                              0x00000001859e5f38 -[NSTextView(NSSharing) shouldChangeTextInRanges:replacementStrings:] + 968
	7   AppKit                              0x00000001861f9d18 -[NSTextView performValidatedReplacementInRange:withAttributedString:] + 196
	8   SwiftUI                             0x00000001ae4223d8 OUTLINED_FUNCTION_6 + 2648
	9   SwiftUI                             0x00000001ae53c724 OUTLINED_FUNCTION_1 + 8004
	10  SwiftUI                             0x00000001ae53bfd4 OUTLINED_FUNCTION_1 + 6132
	11  SwiftUI                             0x00000001ae53ba8c OUTLINED_FUNCTION_1 + 4780
	12  SwiftUI                             0x00000001ae53acb8 OUTLINED_FUNCTION_1 + 1240
	13  SwiftUI                             0x00000001aced8030 OUTLINED_FUNCTION_38 + 907680
	14  SwiftUI                             0x00000001ad00cae4 OUTLINED_FUNCTION_38 + 2171988
	15  SwiftUI                             0x00000001ad0eacc4 objectdestroy.127Tm + 5004
	16  SwiftUI                             0x00000001ae4045e0 OUTLINED_FUNCTION_2 + 31536
	17  SwiftUI                             0x00000001ad0084cc OUTLINED_FUNCTION_38 + 2154044
	18  SwiftUI                             0x00000001acff47b8 OUTLINED_FUNCTION_38 + 2072872
	19  SwiftUI                             0x00000001ad17aa28 objectdestroy.2265Tm + 6976
	20  AttributeGraph                      0x00000001aea237a4 _ZN2AG5Graph11UpdateStack6updateEv + 512
	21  AttributeGraph                      0x00000001aea23fe0 _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 424
	22  AttributeGraph                      0x00000001aea32828 _ZN2AG8Subgraph6updateEj + 848
	23  SwiftUI                             0x00000001ae32a2dc OUTLINED_FUNCTION_5 + 12088
	24  SwiftUI                             0x00000001adc8b68c OUTLINED_FUNCTION_10 + 6360
	25  SwiftUI                             0x00000001ad58fd6c OUTLINED_FUNCTION_58 + 1312
	26  SwiftUI                             0x00000001ad58fc34 OUTLINED_FUNCTION_58 + 1000
	27  libswiftObservation.dylib           0x0000000222ed8558 $s11Observation0A8TrackingV08_installB0_7willSet03didE0yAC_yACYbcSgAGtFZAC2IdOAC5EntryVXEfU_yyYbcfU2_TATm + 48
	28  libswiftObservation.dylib           0x0000000222ed8670 $sIegh_ytIeghr_TRTA + 28
	29  libswiftObservation.dylib           0x0000000222ed682c $s11Observation0A9RegistrarV7ContextV7willSet_7keyPathyx_s03KeyG0Cyxq_GtAA10ObservableRzr0_lFTf4dnn_n + 568
	30  libswiftObservation.dylib           0x0000000222ed725c $s11Observation0A9RegistrarV7willSet_7keyPathyx_s03KeyF0Cyxq_GtAA10ObservableRzr0_lFTf4dnn_n + 60
	31  libswiftObservation.dylib           0x0000000222ed2158 $s11Observation0A9RegistrarV12withMutation2of7keyPath_q0_x_s03KeyG0Cyxq_Gq0_yKXEtKAA10ObservableRzr1_lF + 80
	32  TestSearchStringInViewModel         0x000000010018dbf4 $s27TestSearchStringInViewModel0eF0C12withMutation7keyPath_q_s03KeyJ0CyACxG_q_yKXEtKr0_lF + 284
	33  TestSearchStringInViewModel         0x000000010018d5b8 $s27TestSearchStringInViewModel0eF0C06searchC0SSvs + 156
	34  TestSearchStringInViewModel         0x000000010018d504 $s27TestSearchStringInViewModel0eF0C06searchC0SSvpACTk + 88
	35  libswiftCore.dylib                  0x000000019198c560 $ss26NonmutatingWritebackBufferCfD + 312
	36  libswiftCore.dylib                  0x0000000191bbddb0 _swift_release_dealloc + 56
	37  libswiftCore.dylib                  0x0000000191bbea8c _ZN5swift9RefCountsINS_13RefCountBitsTILNS_19RefCountInlinednessE1EEEE15doDecrementSlowILNS_13PerformDeinitE1EEEbS3_j + 136
	38  libswiftCore.dylib                  0x000000019198dd2c swift_setAtReferenceWritableKeyPath + 244
	39  SwiftUI                             0x00000001ad28b210 OUTLINED_FUNCTION_7 + 1520
	40  SwiftUI                             0x00000001ad28b32c OUTLINED_FUNCTION_7 + 1804
	41  SwiftUI                             0x00000001ae27b25c OUTLINED_FUNCTION_1 + 9376
	42  SwiftUI                             0x00000001ad28b128 OUTLINED_FUNCTION_7 + 1288
	43  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	44  SwiftUI                             0x00000001ae49dac8 objectdestroy.2Tm + 3400
	45  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	46  SwiftUI                             0x00000001adb33b6c OUTLINED_FUNCTION_0 + 9548
	47  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	48  SwiftUI                             0x00000001adb32f34 OUTLINED_FUNCTION_0 + 6420
	49  SwiftUI                             0x00000001adb332dc OUTLINED_FUNCTION_0 + 7356
	50  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	51  SwiftUI                             0x00000001adb32f34 OUTLINED_FUNCTION_0 + 6420
	52  SwiftUI                             0x00000001adb332dc OUTLINED_FUNCTION_0 + 7356
	53  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	54  SwiftUI                             0x00000001adb32f34 OUTLINED_FUNCTION_0 + 6420
	55  SwiftUI                             0x00000001adb332dc OUTLINED_FUNCTION_0 + 7356
	56  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	57  SwiftUI                             0x00000001adb33b9c OUTLINED_FUNCTION_0 + 9596
	58  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	59  SwiftUI                             0x00000001adb33b6c OUTLINED_FUNCTION_0 + 9548
	60  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	61  SwiftUI                             0x00000001adb32f34 OUTLINED_FUNCTION_0 + 6420
	62  SwiftUI                             0x00000001adb332dc OUTLINED_FUNCTION_0 + 7356
	63  SwiftUI                             0x00000001adb31b08 OUTLINED_FUNCTION_0 + 1256
	64  SwiftUI                             0x00000001ae575560 OUTLINED_FUNCTION_29 + 16752
	65  SwiftUI                             0x00000001ae53cb38 OUTLINED_FUNCTION_1 + 9048
	66  SwiftUI                             0x00000001ae53da54 OUTLINED_FUNCTION_1 + 12916
	67  CoreFoundation                      0x0000000182050570 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
	68  CoreFoundation                      0x00000001820e465c ___CFXRegistrationPost_block_invoke + 88
	69  CoreFoundation                      0x00000001820e45a4 _CFXRegistrationPost + 440
	70  CoreFoundation                      0x000000018201f1dc _CFXNotificationPost + 764
	71  Foundation                          0x0000000183111ff0 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
	72  CoreFoundation                      0x0000000182050570 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
	73  CoreFoundation                      0x00000001820e465c ___CFXRegistrationPost_block_invoke + 88
	74  CoreFoundation                      0x00000001820e45a4 _CFXRegistrationPost + 440
	75  CoreFoundation                      0x000000018201f1dc _CFXNotificationPost + 764
	76  Foundation                          0x0000000183111ff0 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
	77  AppKit                              0x00000001859e7ac4 -[NSTextView(NSSharing) didChangeText] + 332
	78  AppKit                              0x0000000185b0b144 _NSDoUserReplaceForCharRange + 452
	79  AppKit                              0x0000000185b4c5d0 -[NSTextView(NSKeyBindingCommands) deleteBackward:] + 664
	80  AppKit                              0x0000000185a91248 -[NSTextView doCommandBySelector:] + 176
	81  AppKit                              0x0000000185a91158 -[NSTextInputContext(NSInputContext_WithCompletion) doCommandBySelector:completionHandler:] + 228
	82  AppKit                              0x00000001859e267c -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) interpretEventAsCommand:forClient:] + 1496
	83  AppKit                              0x00000001859e9fb4 __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke_5 + 360
	84  AppKit                              0x00000001864238b0 __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke_3.711 + 100
	85  AppKit                              0x00000001859e9e08 -[NSTextInputContext tryHandleEvent_HasMarkedText_withDispatchCondition:dispatchWork:continuation:] + 148
	86  AppKit                              0x0000000186423810 __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke.708 + 316
	87  HIToolbox                           0x000000018c7b5804 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_6 + 96
	88  HIToolbox                           0x000000018c650d04 ___ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec_block_invoke + 148
	89  AppKit                              0x000000018641e4f4 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke.186 + 576
	90  AppKit                              0x00000001859e4538 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2 + 100
	91  AppKit                              0x00000001859e4484 -[NSTextInputContext tryHandleTSMEvent_HasMarkedText_withDispatchCondition:dispatchWork:continuation:] + 148
	92  AppKit                              0x00000001859e39fc -[NSTextInputContext handleTSMEvent:completionHandler:] + 2044
	93  AppKit                              0x00000001859e3194 _NSTSMEventHandler + 332
	94  HIToolbox                           0x000000018c5e0894 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1228
	95  HIToolbox                           0x000000018c5dfc98 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 356
	96  HIToolbox                           0x000000018c5dfb28 SendEventToEventTargetWithOptions + 44
	97  HIToolbox                           0x000000018c63ce30 SendTSMEvent_WithCompletionHandler + 432
	98  HIToolbox                           0x000000018c63d380 __SendUnicodeTextAEToUnicodeDoc_WithCompletionHandler_block_invoke + 456
	99  HIToolbox                           0x000000018c63d18c __SendFilterTextEvent_WithCompletionHandler_block_invoke + 228
	100 HIToolbox                           0x000000018c63ce88 SendTSMEvent_WithCompletionHandler + 520
	101 HIToolbox                           0x000000018c63cc38 SendFilterTextEvent_WithCompletionHandler + 260
	102 HIToolbox                           0x000000018c63c86c SendUnicodeTextAEToUnicodeDoc_WithCompletionHandler + 296
	103 HIToolbox                           0x000000018c63c5f8 __utDeliverTSMEvent_WithCompletionHandler_block_invoke_2 + 320
	104 HIToolbox                           0x000000018c63c37c __utDeliverTSMEvent_WithCompletionHandler_block_invoke + 284
	105 HIToolbox                           0x000000018c63c1e0 TSMKeyEvent_WithCompletionHandler + 588
	106 HIToolbox                           0x000000018c640a18 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_5 + 312
	107 HIToolbox                           0x000000018c63bf7c __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_4 + 408
	108 HIToolbox                           0x000000018c63bd34 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_3 + 352
	109 HIToolbox                           0x000000018c63ba10 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_2 + 312
	110 HIToolbox                           0x000000018c63b71c __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke + 312
	111 HIToolbox                           0x000000018c629388 TSMProcessRawKeyEventWithOptionsAndCompletionHandler + 2308
	112 AppKit                              0x00000001864236c4 __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke_3.704 + 148
	113 AppKit                              0x00000001864233a0 __204-[NSTextInputContext tryTSMProcessRawKeyEvent_orSubstitution:dispatchCondition:setupForDispatch:furtherCondition:doubleSpaceSubstitutionCondition:doubleSpaceSubstitutionWork:dispatchTSMWork:continuation:]_block_invoke.687 + 192
	114 AppKit                              0x00000001859e1f50 -[NSTextInputContext tryTSMProcessRawKeyEvent_orSubstitution:dispatchCondition:setupForDispatch:furtherCondition:doubleSpaceSubstitutionCondition:doubleSpaceSubstitutionWork:dispatchTSMWork:continuation:] + 336
	115 AppKit                              0x00000001859e1978 -[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:] + 1456
	116 AppKit                              0x00000001859e1388 -[NSTextInputContext _handleEvent:allowingSyntheticEvent:] + 132
	117 AppKit                              0x00000001859e11e0 -[NSView interpretKeyEvents:] + 156
	118 AppKit                              0x00000001859e1034 -[NSTextView keyDown:] + 524
	119 SwiftUI                             0x00000001ae699dfc OUTLINED_FUNCTION_14 + 38788
	120 SwiftUI                             0x00000001ae69a1a0 OUTLINED_FUNCTION_14 + 39720
	121 SwiftUI                             0x00000001ada85d04 OUTLINED_FUNCTION_0 + 76892
	122 SwiftUI                             0x00000001ada85f14 OUTLINED_FUNCTION_0 + 77420
	123 AppKit                              0x0000000185962810 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 480
	124 AppKit                              0x000000018596245c -[NSWindow(NSEventRouting) sendEvent:] + 284
	125 AppKit                              0x000000018600f9f4 -[NSApplication(NSEventRouting) sendEvent:] + 1604
	126 AppKit                              0x0000000185c5e908 -[NSApplication _handleEvent:] + 60
	127 AppKit                              0x0000000185829d74 -[NSApplication run] + 512
	128 AppKit                              0x0000000185801014 NSApplicationMain + 880
	129 SwiftUI                             0x00000001accb4364 OUTLINED_FUNCTION_12 + 15824
	130 SwiftUI                             0x00000001ad54393c OUTLINED_FUNCTION_3 + 196
	131 SwiftUI                             0x00000001ad98ad60 OUTLINED_FUNCTION_1 + 152
	132 TestSearchStringInViewModel         0x000000010018bbc4 $s27TestSearchStringInViewModel0abcdeF3AppV5$mainyyFZ + 40
	133 TestSearchStringInViewModel         0x000000010018e00c main + 12
	134 dyld                                0x0000000181bfd0e0 start + 2360
)
NSHostingView is being laid out reentrantly while rendering its SwiftUI content. This is not supported and the current layout pass will be skipped.
*** -[NSBigMutableString substringWithRange:]: Range {0, 1} out of bounds; string length 0
(
	0   CoreFoundation                      0x00000001820d0570 __exceptionPreprocess + 176
	1   libobjc.A.dylib                     0x0000000181bc1eb4 objc_exception_throw + 60
	2   Foundation                          0x0000000183131930 -[NSString _newSubstringWithRange:zone:] + 0
	3   AppKit                              0x00000001859e6f28 -[NSTextStorage(NSUndo) _undoRedoAttributedSubstringFromRange:] + 140
	4   AppKit                              0x00000001859fff14 -[NSUndoReplaceCharacters initWithAffectedRange:textStorage:undoManager:replacementRange:] + 112
	5   AppKit                              0x00000001859e5edc -[NSTextView(NSSharing) shouldChangeTextInRanges:replacementStrings:] + 876
	6   AppKit                              0x00000001861f9d18 -[NSTextView performValidatedReplacementInRange:withAttributedString:] + 196
	7   SwiftUI                             0x00000001ae4223d8 OUTLINED_FUNCTION_6 + 2648
	8   SwiftUI                             0x00000001ae53c724 OUTLINED_FUNCTION_1 + 8004
	9   SwiftUI                             0x00000001ae53bfd4 OUTLINED_FUNCTION_1 + 6132
	10  SwiftUI                             0x00000001ae53ba8c OUTLINED_FUNCTION_1 + 4780
	11  SwiftUI                             0x00000001ae53acb8 OUTLINED_FUNCTION_1 + 1240
	12  SwiftUI                             0x00000001aced8030 OUTLINED_FUNCTION_38 + 907680
	13  SwiftUI                             0x00000001ad00cae4 OUTLINED_FUNCTION_38 + 2171988
	14  SwiftUI                             0x00000001ad0eacc4 objectdestroy.127Tm + 5004
	15  SwiftUI                             0x00000001ae4045e0 OUTLINED_FUNCTION_2 + 31536
	16  SwiftUI                             0x00000001ad0084cc OUTLINED_FUNCTION_38 + 2154044
	17  SwiftUI                             0x00000001acff47b8 OUTLINED_FUNCTION_38 + 2072872
	18  SwiftUI                             0x00000001ad17aa28 objectdestroy.2265Tm + 6976
	19  AttributeGraph                      0x00000001aea237a4 _ZN2AG5Graph11UpdateStack6updateEv + 512
	20  AttributeGraph                      0x00000001aea23fe0 _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 424
	21  AttributeGraph                      0x00000001aea32828 _ZN2AG8Subgraph6updateEj + 848
	22  SwiftUI                             0x00000001ae32a2dc OUTLINED_FUNCTION_5 + 12088
	23  SwiftUI                             0x00000001add7f524 OUTLINED_FUNCTION_23 + 74788
	24  SwiftUI                             0x00000001add7dd8c OUTLINED_FUNCTION_23 + 68748
	25  SwiftUI                             0x00000001ad1b6830 OUTLINED_FUNCTION_151 + 56568
	26  SwiftUI                             0x00000001ad1b6878 OUTLINED_FUNCTION_151 + 56640
	27  AppKit                              0x00000001863fd9e0 -[NSTableRowData enumerateAvailableRowViewsIncludingOrphanRows:usingBlock:] + 168
	28  SwiftUI                             0x00000001add7c968 OUTLINED_FUNCTION_23 + 63592
	29  SwiftUI                             0x00000001add7b6ac OUTLINED_FUNCTION_23 + 58796
	30  SwiftUI                             0x00000001add7a0dc OUTLINED_FUNCTION_23 + 53212
	31  SwiftUI                             0x00000001ad44cc64 OUTLINED_FUNCTION_0 + 16392
	32  SwiftUI                             0x00000001ad451e9c __swift_memcpy216_8 + 904
	33  SwiftUI                             0x00000001ae27b25c OUTLINED_FUNCTION_1 + 9376
	34  SwiftUI                             0x00000001ad44c930 OUTLINED_FUNCTION_0 + 15572
	35  SwiftUI                             0x00000001adeecb6c __swift_allocate_boxed_opaque_existential_1Tm + 268
	36  AttributeGraph                      0x00000001aea237a4 _ZN2AG5Graph11UpdateStack6updateEv + 512
	37  AttributeGraph                      0x00000001aea23fe0 _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 424
	38  AttributeGraph                      0x00000001aea32828 _ZN2AG8Subgraph6updateEj + 848
	39  SwiftUI                             0x00000001ae32a2dc OUTLINED_FUNCTION_5 + 12088
	40  SwiftUI                             0x00000001ae401e6c OUTLINED_FUNCTION_2 + 21436
	41  SwiftUI                             0x00000001ae3feb10 OUTLINED_FUNCTION_2 + 8288
	42  SwiftUI                             0x00000001ada81a84 OUTLINED_FUNCTION_0 + 59868
	43  SwiftUI                             0x00000001ada8d0a0 OUTLINED_FUNCTION_0 + 106488
	44  SwiftUI                             0x00000001ada81f18 OUTLINED_FUNCTION_0 + 61040
	45  AppKit                              0x000000018584d6f4 +[NSAnimationContext runAnimationGroup:] + 56
	46  SwiftUI                             0x00000001ada81960 OUTLINED_FUNCTION_0 + 59576
	47  SwiftUI                             0x00000001ada81f58 OUTLINED_FUNCTION_0 + 61104
	48  AppKit                              0x00000001862c8af4 ___NSViewLayout_block_invoke + 592
	49  AppKit                              0x0000000185878714 NSPerformVisuallyAtomicChange + 108
	50  AppKit                              0x000000018587d244 _NSViewLayout + 96
	51  AppKit                              0x00000001862bf0cc __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke + 364
	52  AppKit                              0x0000000185878714 NSPerformVisuallyAtomicChange + 108
	53  AppKit                              0x000000018587d1d8 -[NSView _layoutSubtreeWithOldSize:] + 100
	54  AppKit                              0x00000001862bf210 __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke + 688
	55  AppKit                              0x0000000185878714 NSPerformVisuallyAtomicChange + 108
	56  AppKit                              0x000000018587d1d8 -[NSView _layoutSubtreeWithOldSize:] + 100
	57  AppKit                              0x00000001862bfbb4 __56-[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:]_block_invoke + 796
	58  AppKit                              0x0000000185878714 NSPerformVisuallyAtomicChange + 108
	59  AppKit                              0x000000018587cd98 -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 100
	60  AppKit                              0x0000000185878714 NSPerformVisuallyAtomicChange + 108
	61  AppKit                              0x000000018587cd28 -[NSView layoutSubtreeIfNeeded] + 96
	62  AppKit                              0x000000018656af20 -[NSWindow(NSConstraintBasedLayoutInternal) _layoutViewTree] + 104
	63  AppKit                              0x000000018656b0a8 -[NSWindow(NSConstraintBasedLayoutInternal) layoutIfNeeded] + 240
	64  AppKit                              0x00000001858db94c __NSWindowGetDisplayCycleObserverForLayout_block_invoke + 364
	65  AppKit                              0x00000001858daee8 NSDisplayCycleObserverInvoke + 168
	66  AppKit                              0x00000001858dab44 NSDisplayCycleFlush + 644
	67  QuartzCore                          0x000000018a11dfb4 _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 120
	68  QuartzCore                          0x000000018a11cd54 _ZN2CA11Transaction6commitEv + 320
	69  AppKit                              0x000000018595eec8 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 272
	70  AppKit                              0x0000000186304558 ___NSRunLoopObserverCreateWithHandler_block_invoke + 64
	71  CoreFoundation                      0x000000018205adf0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
	72  CoreFoundation                      0x000000018205acdc __CFRunLoopDoObservers + 532
	73  CoreFoundation                      0x000000018205a30c __CFRunLoopRun + 776
	74  CoreFoundation                      0x00000001820599ac CFRunLoopRunSpecific + 608
	75  HIToolbox                           0x000000018c608448 RunCurrentEventLoopInMode + 292
	76  HIToolbox                           0x000000018c6080d8 ReceiveNextEventCommon + 220
	77  HIToolbox                           0x000000018c607fdc _BlockUntilNextEventMatchingListInModeWithFilter + 76
	78  AppKit                              0x00000001858368a4 _DPSNextEvent + 660
	79  AppKit                              0x0000000186010980 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716
	80  AppKit                              0x0000000185829d50 -[NSApplication run] + 476
	81  AppKit                              0x0000000185801014 NSApplicationMain + 880
	82  SwiftUI                             0x00000001accb4364 OUTLINED_FUNCTION_12 + 15824
	83  SwiftUI                             0x00000001ad54393c OUTLINED_FUNCTION_3 + 196
	84  SwiftUI                             0x00000001ad98ad60 OUTLINED_FUNCTION_1 + 152
	85  TestSearchStringInViewModel         0x000000010018bbc4 $s27TestSearchStringInViewModel0abcdeF3AppV5$mainyyFZ + 40
	86  TestSearchStringInViewModel         0x000000010018e00c main + 12
	87  dyld                                0x0000000181bfd0e0 start + 2360
)
```

I’m attaching a demo video which uses @Bindable, but the same thing happens with @State or just “var” and a bindable variable created in code.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!