fix(macos): give snapshot nodes with a non-finite AX rect no rect

Merged
JA
2mo ago
+33-6

Summary

On macOS, rectAttribute built RectResponse straight from the AX position and size. SwiftUI reports lazy containers (LazyVGrid, LazyVStack) scrolled or sized out of view as an AXOpaqueProviderGroup at (inf, inf, 0, 0). JSONEncoder throws on that value, so one node failed the whole snapshot: EncodingError.invalidValue: inf (Double). Path: data.nodes[N].rect.x.

rectAttribute now returns nil when any component is non-finite. Nodes already allow a nil rect (they are not hittable), and the other rectAttribute callers already handle nil. Touches 2 files in apple/macos-helper.

The iOS runner and Android paths were not changed: the runner already skips null/empty frames and I found no same-pattern encoding of raw AX doubles there. I did not exercise them with a non-finite frame.

Related to #3323 (independent, no dependency). No existing issue found.

Validation

Tested at 6ddff2579.

  • pnpm check:affected --run: all runnable checks passed (macos-helper lanes are GitHub-authoritative).
  • pnpm test:macos-helper: passes, including RectResponseTests on the pure finiteRectResponse(position:size:) that rectAttribute calls: a finite rect is kept, and +inf, -inf and NaN in each component give nil.
  • Live run (evidence in this comment): on a SwiftUI app with an AXOpaqueProviderGroup at (inf, inf, 0, 0), a helper built from main fails snapshot with EncodingError.invalidValue: inf; a helper built from this branch succeeds, with that node present, no rect, hittable: false, and the nodes after it listed. The live helper was built from 099be379a, which has the same content as 6ddff2579. Only +inf occurred live; NaN and -inf are covered by the unit tests, and only the live run covers the rectAttribute wiring.