Skip to content

✨ Render SwiftUI #Previews with Vizzly - #351

Merged
Robdel12 merged 19 commits into
mainfrom
rd/swift-preview-sdk
Sep 12, 2026
Merged

✨ Render SwiftUI #Previews with Vizzly#351
Robdel12 merged 19 commits into
mainfrom
rd/swift-preview-sdk

Conversation

@Robdel12

@Robdel12 Robdel12 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Why

Vizzly's Swift SDK can capture screenshots from UI tests, but it cannot render an app's SwiftUI #Preview declarations directly. This adds that workflow while keeping the existing Vizzly and VizzlyXCTest APIs and target dependencies unchanged.

Approach

The @vizzly-testing/swift package registers vizzly previews. The command builds the selected app in Xcode's normal DerivedData, reads its generated preview registries, and uses VizzlyPreviewRuntime to render them in a booted Simulator. Apps add the runtime as a dynamic Swift Package product and install it once from the app initializer.

Project, shared scheme, and Simulator selection are automatic when there is one clear choice. --include <pattern> limits a run to one preview or a small group. Previews render in one app process, and Vizzly relaunches the app with the remaining work if a preview crashes or times out.

Captured screenshots use the existing Vizzly paths: a project-local TDD server receives local runs, configured credentials create a cloud build, and --no-upload keeps the PNGs and manifest local.

Safety and support

Xcode builds, embeds, and signs the runtime as a normal package dependency. The CLI does not modify the built app or pass Vizzly credentials into the app process.

The app initializer and some scene lifecycle code can run during capture. VizzlyPreviewRuntime.isCapturing lets apps skip services that should not run in that environment. Preview capture currently supports Xcode 26.6 on arm64 Macs, iOS 17 or newer Simulators, scene-based apps, fixed layouts, and portrait or landscape orientation traits.

Evidence

The checked-in iOS fixture verifies preview discovery, name filtering, fixed-layout dimensions, repeat captures, safe output replacement, failure recovery, and uploads through the local Vizzly server. The JavaScript suite, Swift package suite, package checks, and real Simulator workflow pass.

Render existing stock #Preview declarations from the built app target through a Simulator-injected Swift runtime. Add the Vizzly CLI plugin, two-preview fixture, manifest output, and repeatable end-to-end coverage.
Select the device automatically when exactly one available iOS Simulator is booted. Keep ambiguous and stale-device cases explicit, actionable, and covered by the real preview capture path.
Harden the native renderer for real app targets, repeatable output, scheme selection, capture timeouts, and explicit compatibility failures. Ship the npm plugin through Swift releases, add CI coverage and complete fixture metadata, and verify package auto-discovery against a real iOS project.
Route native preview captures through the existing screenshot client for local TDD and cloud builds. Record upload outcomes, preserve explicit local-only capture, and cover the real HTTP boundary plus stock-preview naming and metadata.
Tighten managed output and plugin capability checks, run the native preview fixture during Swift releases, and replace duplicated Swift docs with focused XCTest and #Preview guides.
Move preview capture to a normal dynamic Swift Package dependency so Xcode owns building, embedding, and signing the runtime. Remove CLI injection and app mutation, add setup diagnostics, and prove the public integration on Simulator and device builds.
The macos-latest label moved to macOS 26, which no longer includes Xcode 16.2 or 16.4. Keep the existing compatibility matrix on the macOS 15 arm64 image where both toolchains are installed.
Keep successful captures when individual previews fail, support common layout traits, and make the beta installable through exact npm and SwiftPM release tags. Also repair the Swift CI runner and rebase drift against the current upload contract.
@Robdel12
Robdel12 force-pushed the rd/swift-preview-sdk branch from 71f2aaf to d39b206 Compare September 11, 2026 05:04
The preview plugin uses the isolated screenshot service introduced in this branch. Require and document the matching CLI beta so a fresh PitStop install cannot silently select the older public CLI.
Remove the Swift-only screenshot service and use the CLI's established public client for local and cloud uploads. This keeps the plugin compatible with the published 0.36.0 CLI.
@Robdel12 Robdel12 changed the title ✨ Render stock SwiftUI previews with Vizzly ✨ Render SwiftUI #previews with Vizzly Sep 11, 2026
@Robdel12 Robdel12 changed the title ✨ Render SwiftUI #previews with Vizzly ✨ Render SwiftUI #Previews with Vizzly Sep 11, 2026
Let Xcode use its normal build products so repeated preview captures are incremental instead of paying for a clean build on every run.
Add the shared --include glob convention and resolve preview names in one lightweight app launch so local iteration renders only the requested previews.
Render preview registries in one Simulator process and relaunch only after a crash or timeout. Keep filtering in the same launch, preserve completed screenshots across recovery, and verify the workflow with an intentional crashing preview.
Document batched process reuse, progress-based timeouts, and the deterministic-data requirement for async preview content.
Clarify that preview capture is opt-in and leaves the existing XCTest products unchanged. Keep the preview guide direct, trim unreleased implementation history, and include every linked guide in the npm package.
Keep plugin documentation in the Swift package, remove prerelease installation language, and describe only the implementation that ships. The Swift release workflow now publishes a normal stable release.
Use the production 0.1.1 package version in the Swift guides. An exact rule prevents Xcode from selecting unrelated CLI tags from the shared repository.
Remove renderer internals and exploration context from the public guides. Keep the install, capture, upload, CI, safety, and troubleshooting steps users need.
Show Swift preview defaults inside the normal Vizzly config and keep shared comparison settings at the top level.
@Robdel12
Robdel12 merged commit 51c6c69 into main Sep 12, 2026
34 of 36 checks passed
@Robdel12
Robdel12 deleted the rd/swift-preview-sdk branch September 12, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant