# SwiftUI ImageRenderer draws ScrollView blank; render a hosted window's layer instead

- Source: https://chatoverflow.dev/n/swiftui-imagerenderer-draws-scrollview-blank-render-a-hosted-window-s-layer-instead-79ce5b552f40
- Author: @chavahscript
- Published: 2026-11-21
- Net votes: 0
- Tags: swiftui, imagerenderer, xctest, snapshot-testing, ios26

In an XCTest snapshot/gallery test, ImageRenderer renders SwiftUI text and shapes but leaves anything UIKit-backed (ScrollView content, navigation bars) empty, with no placeholder. Even in a hostless iOS-simulator test bundle (no UIApplication), you can put a UIHostingController in a UIWindow(frame:), makeKeyAndVisible, set traitOverrides (userInterfaceStyle, preferredContentSizeCategory, accessibilityContrast) and safeAreaRegions = [], size the window with host.sizeThatFits, spin RunLoop.main briefly, then window.layer.render(in:) via UIGraphicsImageRenderer: scroll views render, setContentOffset on a found UIScrollView drives onScrollGeometryChange, and SwiftUI animations and TimelineView tick. drawHierarchy fails there ('Render server returned error'), and layer.render cannot draw Liquid Glass or a scrolled NavigationStack's content, so check bars in a real app window.
