Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SwiftUI Logic Also use RenderingError enum #210

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

NicoHinderling
Copy link
Collaborator

@NicoHinderling NicoHinderling commented Nov 21, 2024

We had an issue where some mac previews were failing to render, and it was unclear why. We should have had the "zero width" situation handled, but it was only configured for UIKit rendering, not AppKit rendering.

I went ahead and made the AppKit/SwiftUI rendering use the same error enum type. Our backend/web should then parse this correctly

import UIKit
import AccessibilitySnapshotCore
import SnapshotSharedModels
import CoreFoundation

public enum RenderingError: Error {
case failedRendering(CGSize)
case maxSize(CGSize)
case expandingViewTimeout(CGSize)
}
Copy link
Collaborator Author

@NicoHinderling NicoHinderling Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this outside of the #if canImport(UIKit) && !os(visionOS) && !os(watchOS) && !os(tvOS) block. I had to import CoreFoundation to get CGSize, but I think that's fine for both UIKit / AppKit purposes

lmk otherwise

@@ -41,7 +37,7 @@ public class SwiftUIRenderingStrategy: RenderingStrategy {
if let image {
completion(SnapshotResult(image: .success(image), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot))
} else {
completion(SnapshotResult(image: .failure(SwiftUIRenderingError.renderingError), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot))
completion(SnapshotResult(image: .failure(RenderingError.failedRendering(image?.size ?? .zero)), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image is always null here because this is in the else block of the if let so we can just use .zero?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

@NicoHinderling NicoHinderling merged commit cdbf9cc into main Nov 21, 2024
7 checks passed
@NicoHinderling NicoHinderling deleted the nico-swiftui-error-test branch November 21, 2024 22:20
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.

2 participants