Skip to content

fix(mobile): pasting or attaching a file no longer crashes iOS - #812

Merged
trancong12102 merged 1 commit into
mainfrom
fix/ios-image-paste-crash
Nov 28, 2026
Merged

trancong12102 merged 1 commit into
mainfrom
fix/ios-image-paste-crash

Conversation

@trancong12102

Copy link
Copy Markdown
Contributor

On iOS, pasting an image into the composer (or attaching any file) crashed the app as soon as the upload started. expo-file-system 58.0.15, pulled in by the dependency update in #793, creates its background URLSession from the module queue UploadTask.start runs on and registers it through ExpoAppDelegateSubscriberRepository, a @MainActor class, so Swift's isolation check traps:

EXC_BREAKPOINT  queue: expo.modules.AsyncFunctionQueue
_swift_task_checkIsolatedSwift
ExpoAppDelegateSubscriberRepository.getSubscriberOfType
NetworkTaskSessionManager.createBackgroundSession()
NetworkTaskSessionManager.session(for:)
FileSystemUploadTask.start(url:file:options:promise:)

Upstream: expo/expo#54360 and #54432, closed for a missing repro. Expo's main branch still has the bug.

Fix

  • patches/expo-file-system@58.0.15.patch: NetworkTaskSessionManager.session(for:) resolves sessions on the main thread, hopping there synchronously from the upload queue. Downloads already start on main. This keeps the session registration synchronous, and the unsynchronized lazy sessions stay on one thread.
  • apps/mobile/package.json: expo-file-system goes into expo.autolinking.buildFromSource. Without it, iOS links Expo's precompiled XCFramework and ignores the patch. The first rebuild still crashed until this was added.
  • pnpm-workspace.yaml: the patch entry, plus the usual overrides pin for patched packages.

Android doesn't have the bug, but its native fingerprint changes because buildFromSource is not platform-specific. This matches expo-network, which is already in the same list.

Verification

iOS 27.2 simulator, dev client built from this branch, isolated dev server:

  • Before: copying a photo in Photos and choosing Paste in the composer crashed with the stack above (crash report captured).
  • After: the paste shows the pasted-image.jpeg 401 KB chip, no crash report, and the 409,695-byte file reaches the server's attachments directory.
  • vp run check:changed passes.

Review: Gemini 4 Neon (xhigh) found nothing blocking. Its finding on the registration race is applied (synchronous main-thread resolution instead of a deferred Task). Not taken: an iOS-only buildFromSource list, because it replaces the shared list and would duplicate all 11 entries. Also not taken: patching the legacy module, which nothing in the app or its dependencies reaches.

Made with Claude Opus 5.5 in Claude Code (Onicode).

🤖 Generated with Claude Code

expo-file-system 58.0.15 creates its background URL session, and registers it
through the main-actor ExpoAppDelegateSubscriberRepository, from the module
queue an upload starts on, so the first upload trips Swift's isolation check
(expo/expo#54360). Resolve network sessions on the main thread, as downloads
already do, and build the module from source so iOS uses the patch rather than
the precompiled XCFramework.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trancong12102
trancong12102 merged commit 7a1a7b5 into main Nov 28, 2026
18 checks passed
@trancong12102
trancong12102 deleted the fix/ios-image-paste-crash branch November 28, 2026 05:35
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