Nested DisclosureGroups Inside SwiftUI Form Crash Accessibility Snapshots: Five Multi-Device Fixes from GoodCRM Wave 6
Running Wave 6 (c50b43a) UI automation across iPhone, iPad 3-column split, and Mac uncovered five SwiftUI bugs that unit tests never saw: nested DisclosureGroups crashing accessibility snapshots, plain row hit-testing, compact maps starving results, 350ms touchRecent debouncing, and stale .searchHit stack routes.
GoodCRM (1.0) is live on the US App Store (id6837223780), with HarmonyOS in preparation. One SwiftUI codebase serves iPhone compact navigation, iPad 3-column split view, and macOS windows — and unit tests on Model4LocalService tell you nothing about how Form and NavigationStack behave across those three layouts.
When Wave 6 (c50b43a, building on aab31f9) ran 10 iPhone UI suites and 3 iPad split-view UI suites on iOS 18.2 simulators, all storage assertions were green, and SwiftUI broke in five concrete ways.
1. Nested DisclosureGroup Inside Form Crashes Accessibility Snapshots
AttachmentImportForm4, AttachmentDetail4, and RecordDetail4 used DisclosureGroup inside Form to hide technical details like 64-character SHA-256 digests. Worse, RecordDetail4’s immutable revisions section nested a DisclosureGroup("校验摘要与技术标识") directly inside an outer DisclosureGroup("修订 N").
During XCUITest runs on iOS 18.2, taking an accessibility snapshot of a Form containing those nested DisclosureGroup rows crashed inside SwiftUI’s List backing host.
The fix in AttachmentViews.swift and RecordViews.swift replaced those DisclosureGroup blocks with explicit @State sets (showTechnicalDigest, expandedRevisions: Set<String>, expandedRevisionHashes: Set<String>) and plain Button toggles:
Button {
if revExpanded { expandedRevisions.remove(revID) } else { expandedRevisions.insert(revID) }
} label: {
HStack {
Text("修订 \(item.revision_number?.value.rawValue ?? 0)" + (item.id == row.revision_id ? " · 当前" : ""))
.foregroundStyle(Color(C13.ink))
Spacer()
Image(systemName: revExpanded ? "chevron.up" : "chevron.down")
.font(.caption)
.foregroundStyle(Color(C13.muted))
}
}
.buttonStyle(.plain)
While touching AttachmentDetail4, I also moved Section("状态") (attachment.saved, attachment.availability) above the thumbnail section so large image previews don’t push the save status off-screen.
2. Plain Button Hit-Shapes and Keyboard-Safe Form Scrolling
Custom row buttons inside Form and List easily drop taps on spacer regions unless .buttonStyle(.plain) and explicit .contentShape(Rectangle()) + label padding are wired consistently (a pattern we also had to enforce on sidebar settings rows in G-P1-03).
On long edit forms, soft keyboards also trapped fields at the bottom of the scroll view. Commit c50b43a switched ActionForm4, AddressEditorForm4, MatterForm4, and RecordForm4 from .scrollDismissesKeyboard(.interactively) to .scrollDismissesKeyboard(.immediately) and added a "完成" keyboard toolbar button (record.keyboard.dismiss) in RecordForm4. In AddressesUITests.swift, AttachmentsUITests.swift, and ShortcutsUITests.swift, blind swipeUp() calls were updated to bidirectional reveal and upper-screen drags (dy: 0.42 -> 0.16) while the keyboard is visible, without relaxing any functional assertion.
3. Compact-Width Maps Crowding Out Nearby Results
In NearbyView4 (AddressViews.swift), iPad split view gives the map and result list plenty of room. On iPhone compact width (columnSelection == nil), the old layout stacked a 240pt-tall Map followed by the full filterSection before any results or empty-state message.
Users opening Tab 5 on an iPhone saw 80% map and filter controls and zero customer rows above the fold.
c50b43a dropped the map height to 148pt on compact width (keeping 220pt in split mode), moved filterSection below the result sections, and wrapped CRMEmptyState inside a Section so it renders properly inside List.
4. .task(id: ref) with a 350ms Delay for touchRecent
CustomerDetail.swift previously hit a timing bug (G-P2-03): calling workspace.touchRecent(ref) inside .onDisappear meant navigating from customer A to customer B fired B’s appear before A’s disappear, putting A back at the top of Recent Customers.
Removing .onDisappear in Wave 3 fixed the clobbering, but Wave 6 caught that touchRecent was no longer firing at all when opening a detail page. Writing immediately in .onAppear isn’t ideal either when arrow-keying or swiping past rows in iPad 3-column mode. The fix uses SwiftUI’s .task(id: ref) cancellation lifecycle:
.task(id: ref) {
try? await Task.sleep(for: .milliseconds(350))
guard !Task.isCancelled, summary != nil else { return }
workspace.touchRecent(ref)
}
Fast skims cancel the task before 350ms; dwelling on a customer detail view records touchRecent(ref) reliably.
5. Cleaning .searchHit Routes on Back Navigation
Jumping from global search closes the search sheet, routes the workspace to the hit customer/matter/record, and shows a "返回搜索结果" toolbar button (search.back.results).
In Wave 6 multi-hop navigation, tapping "返回搜索结果" or navigating back called workspace.returnToSearchResults() without popping .searchHit routes from tabPaths and splitDetailPath, leaving stale detail views stacked behind the search overlay. Extracting returnFromSearchHit() in WorkspaceView.swift strips all .searchHit routes from both tabPaths and splitDetailPath before reopening search results.
Wave 6 Verification Scope
PROGRESS.md records the Wave 6 totals after these fixes: 464/0 Apple host tests, 549/0 HarmonyOS host tests, 10/10 iPhone simulator UI suites (later expanded to 11/11), 3/3 iPad 3-column simulator UI suites, GoodCRMMac launch smoke, assembleHap, and 122/0 Python tool tests. Physical iPad and HarmonyOS tablet hardware remained not_run.
Comments