Skip to content

Fix SwiftUI Previews#2135

Open
xquezme wants to merge 1 commit intoTextureGroup:masterfrom
xquezme:xzme/swiftui-preview-fix
Open

Fix SwiftUI Previews#2135
xquezme wants to merge 1 commit intoTextureGroup:masterfrom
xquezme:xzme/swiftui-preview-fix

Conversation

@xquezme
Copy link
Copy Markdown
Collaborator

@xquezme xquezme commented Mar 3, 2026

Summary

Replaced internal main-thread assertions using ASDisplayNodeCAssertMainThread() with explicit [NSThread isMainThread] checks in ASInternalHelpers.mm.

Why this change

SwiftUI Previews run in a separate lightweight process (PreviewHost / XCPreviewAgent). While Thread.isMainThread / [NSThread isMainThread] returns true (because PreviewHost fakes the Foundation main thread for compatibility with SwiftUI, UIKit, and @MainActor), lower-level or custom main-thread checks (like the previous macro) could fail or behave inconsistently.

This caused assertion failures or skipped initialization/cleanup logic during preview rendering, leading to crashes or broken previews.

pthread_main_np() [NSThread isMainThread]
Returns false (0) Returns true
Checks if current pthread is the original process bootstrap thread Checks if current thread is the Foundation-designated main thread
Not affected by PreviewHost fake-main-thread logic Fully affected — PreviewHost overrides/fakes it as main thread
Does not match SwiftUI / MainActor expectations Matches SwiftUI / UIKit / MainActor expectations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant