Skip to content

fix(mobile): adopt the iOS scene lifecycle - #8296

Closed
bbingz wants to merge 4 commits into
stablyai:mainfrom
bbingz:bbingz/mobile-ios-scene-lifecycle
Closed

bbingz wants to merge 4 commits into
stablyai:mainfrom
bbingz:bbingz/mobile-ios-scene-lifecycle

Conversation

@bbingz

@bbingz bbingz commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Without this, the iOS app does not launch: Expo SDK 55 emits an AppDelegate-owned UIWindow, which the iOS 27 SDK aborts at startup, and mobile/ ships no scene manifest today — window ownership and launch options still live on AppDelegate.

  • add the iOS scene manifest and a generated SceneDelegate.swift for current UIKit scene lifecycle requirements
  • transform the React Native AppDelegate bootstrap so window ownership and launch options move to SceneDelegate
  • forward cold- and warm-launch custom URLs through the scene callbacks
  • make the config plugin idempotent only for a fully migrated project and fail closed on partial scene artifacts
  • verify that SceneDelegate.swift is actually in the application target's Sources build phase; propagate linking failures instead of deferring them to Xcode compile time

Checkable without Xcode: cold- and warm-launch custom-URL forwarding through the scene callbacks, covered by mobile/src/config/ios-uikit-scene-lifecycle-transform.test.ts (scene URL and universal-link events) and mobile/src/transport/pairing.test.ts (the scene-aware URL registry, plus its fallback to the legacy initial URL).

This is the iOS scene-lifecycle replacement extracted from #7949. It intentionally excludes host editing and device identity.

Refs #7949

Screenshots

No visual change.

Testing

  • focused transform/plugin tests: 1 file / 10 tests
  • mobile TypeScript
  • mobile oxlint
  • both plugin files node --check
  • Expo public config parse includes the plugin
  • targeted oxfmt --check
  • pnpm check:max-lines-ratchet
  • git diff --check origin/main...HEAD
  • RED-to-GREEN coverage for partial migration, source-add exceptions, missing target membership, and already-linked idempotence

Native verification needed from a maintainer

Not runnable in this environment, and still the final gate for a native project mutation: Expo prebuild, and an Xcode build on simulator or a physical iOS device. Electron/E2E/GUI does not apply — every changed file is under mobile/.

AI Review Report

The initial independent gate found two blockers: partial scene migrations could be silently accepted, and Xcode source-link failures were swallowed. Both were reproduced and fixed.

Final independent verdict: spec PASS / quality APPROVED. A previously migrated AppDelegate is accepted only when its marker and launch-options property are present and it no longer owns a UIWindow or starts React Native. The Xcode mutation now confirms the PBXFileReference → PBXBuildFile → application PBXSourcesBuildPhase chain for SceneDelegate.swift and throws otherwise.

Security Audit

  • no new network, credential, command-execution, storage, or native-permission surface
  • custom URL forwarding uses the existing React Native Linking path
  • config mutation fails closed instead of writing a partially valid native project
  • no dependency or unrestricted IPC changes

Compatibility

The plugin registers only iOS config mods. Android, desktop macOS/Linux/Windows, SSH, keyboard, filesystem, and Git-provider behavior are unchanged. The AppDelegate rewrite is scoped to the known Expo SDK 55 React Native template and explicitly rejects unknown partial states.

Notes

Validation used Node 26.5.0 while the repository declares Node 24.

ELI5

The mobile iOS app is updated for the modern scene lifecycle: window ownership and launch options move to SceneDelegate, and custom URL opens work for cold and warm launches. That matches current iOS requirements and keeps deep links reliable.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an Expo iOS config plugin for UIKit scene lifecycle support, including SceneDelegate generation, AppDelegate migration, Info.plist configuration, Xcode source linking, and validation tests. Pairing deep-link handling now uses a shared helper that prefers scene-aware linking URLs and falls back to legacy initial URLs across the app’s pairing routes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: adopting the iOS scene lifecycle for the mobile app.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, compatibility, and notes sections with relevant details.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AmethystLiang AmethystLiang self-assigned this Jul 11, 2026
@AmethystLiang
AmethystLiang self-requested a review July 11, 2026 16:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
mobile/src/transport/pairing.test.ts (1)

46-66: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a test for the getInitialURL rejection path.

The .catch(() => null) branch in getInitialPairingCode is a deliberate error-handling path that is not covered by tests. If someone removes the .catch(), the test suite wouldn't detect the regression. Adding a test that verifies the function returns null when getInitialURL rejects closes this gap.

♻️ Suggested test addition
   it('falls back to the legacy initial URL when the scene registry is empty', async () => {
     expect(
       await getInitialPairingCode({
         getLinkingURL: () => null,
         getInitialURL: async () => 'orca://pair?code=legacy-code'
       })
     ).toBe('legacy-code')
   })
+
+  it('returns null when the legacy initial URL rejects', async () => {
+    expect(
+      await getInitialPairingCode({
+        getLinkingURL: () => null,
+        getInitialURL: async () => {
+          throw new Error('native module unavailable')
+        }
+      })
+    ).toBeNull()
+  })
+
+  it('returns null when no URL is available from either source', async () => {
+    expect(
+      await getInitialPairingCode({
+        getLinkingURL: () => null,
+        getInitialURL: async () => null
+      })
+    ).toBeNull()
+  })
mobile/plugins/ios-uikit-scene-lifecycle-transform.js (1)

125-150: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Fail-closed logic is sound; brittle exact-match risks unnecessary hard failures.

rewriteAppDelegate's intentional throw-on-ambiguity/throw-on-no-match design (validated by the test suite) is good, but the oldBootstrap template (Lines 135-141) is matched via a plain String.replace requiring byte-for-byte equality (whitespace, indentation, line endings). Any drift in the Expo/Xcode-generated AppDelegate.swift (e.g., a future Expo SDK patch reformatting the template, or a stray trailing space) will trip the "pattern not found" throw and hard-fail the entire iOS prebuild for every developer, even though the content is functionally unchanged.

Consider normalizing whitespace/line endings before matching (or matching with a whitespace-tolerant regex) while preserving the fail-closed behavior for genuinely different content.

♻️ Example: normalize before matching
+function normalizeForMatch(str) {
+  return str.replace(/\r\n/g, '\n').replace(/[ \t]+\n/g, '\n')
+}
+
 function rewriteAppDelegate(contents) {
   if (contents.includes(MIGRATED_BOOTSTRAP_MARKER)) {
     if (hasAppDelegateOwnedBootstrap(contents)) {
       throw new Error(
         'ios-uikit-scene-lifecycle: partial scene lifecycle migration detected; refuse ambiguous AppDelegate rewrite'
       )
     }
     return contents
   }

   const oldBootstrap = `#if os(iOS) || os(tvOS)
     window = UIWindow(frame: UIScreen.main.bounds)
     factory.startReactNative(
       withModuleName: "main",
       in: window,
       launchOptions: launchOptions)
 `#endif``
   const newBootstrap = `    // Why: ${MIGRATED_BOOTSTRAP_MARKER}`
-  const rewritten = contents.replace(oldBootstrap, newBootstrap)
-  if (rewritten === contents) {
+  const normalizedContents = normalizeForMatch(contents)
+  if (!normalizedContents.includes(oldBootstrap)) {
     throw new Error(
       'ios-uikit-scene-lifecycle: AppDelegate bootstrap pattern not found; refuse silent no-op rewrite'
     )
   }
-  return rewritten
+  return normalizedContents.replace(oldBootstrap, newBootstrap)
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7799d7ee-2eb4-433b-ab46-aa55599639aa

📥 Commits

Reviewing files that changed from the base of the PR and between f7f1b4f and 8abb0b5.

📒 Files selected for processing (7)
  • mobile/app/_layout.tsx
  • mobile/app/pair.tsx
  • mobile/plugins/ios-uikit-scene-lifecycle-transform.js
  • mobile/plugins/ios-uikit-scene-lifecycle.js
  • mobile/src/config/ios-uikit-scene-lifecycle-transform.test.ts
  • mobile/src/transport/pairing.test.ts
  • mobile/src/transport/pairing.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/plugins/ios-uikit-scene-lifecycle.js

Comment thread mobile/src/transport/pairing.ts Resolved
@bbingz

bbingz commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Addressed CodeRabbit: wrap getLinkingURL() in try/catch for symmetry with getInitialURL().catch(() => null) so scene-lifecycle cold starts cannot reject pairing deep-links.

@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz
bbingz force-pushed the bbingz/mobile-ios-scene-lifecycle branch 2 times, most recently from 4468c6a to 1fb3aaf Compare July 14, 2026 00:38
@bbingz

bbingz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (34c160442f9e77d8162b4c54ecd9b39f0ba6a4f2). Conflicts resolved in: mobile/app/_layout.tsx and pairing.test.ts (kept main's relay recovery import + scene-aware getInitialPairingCode). Ready for re-review.

@bbingz
bbingz force-pushed the bbingz/mobile-ios-scene-lifecycle branch from a18f441 to 3010d26 Compare July 22, 2026 01:34
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
bbingz and others added 4 commits August 6, 2026 07:44
Guard synchronous Linking URL reads the same way as getInitialURL so a
throwing Expo registry does not reject cold-start pair deep-links.
Ensure scene-registry failures still recover via getInitialURL.
@bbingz
bbingz force-pushed the bbingz/mobile-ios-scene-lifecycle branch from 3010d26 to aace8a8 Compare August 5, 2026 23:44
@bbingz

bbingz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing as part of fork PR backlog cleanup.

This branch is long-conflicted (DIRTY) against current main and is not on the active campaign rebase list. Feel free to reopen or cut a fresh PR from an updated branch if the change is still needed.

@bbingz bbingz closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants