Skip to content

Conversation

@itsmeichigo
Copy link
Contributor

@itsmeichigo itsmeichigo commented Dec 3, 2025

Closes WOOMOB-1830
Also closes WOOMOB-1836

Description

When migrating to UIScene lifecycle in #16230, we moved AppCoordinator from AppDelegate to UISceneDelegate. Since the authenticator is initialized as part of AppCoordinator, the app can crash if a user launches the app while authenticated with site credentials. The crash chain is below:

  1. AppDelegate.willFinishLaunchingWithOptions (line 53) starts
  2. Line 60: Calls stores.initializeAfterDependenciesAreInitialized()
    → This calls restoreSessionSiteIfPossible() (DefaultStoresManager.swift:179)
    → Which calls restoreWordPressSite(with: url) (line 747)
    → Which calls WordPressAuthenticator.fetchSiteInfo (line 782)
    → 💥 CRASH: WordPressAuthenticator.shared wasn't initialized yet!
  3. Much later, SceneDelegate.scene(_:willConnectTo:options:) is called
  4. Line 20: AppCoordinator is created
    • In AppCoordinator.init(), line 67 calls configureAuthenticator()
    • Which calls authenticationManager.initialize() at line 241
    • But it's too late - the crash already happened!

The solution is to move the initialization of the coordinator from AppCoordinator's configureAuthenticator to AppDelegate before initializeAfterDependenciesAreInitialized is triggered.

Test Steps

The crash is a timing issue - it requires that WordPressSiteAction.fetchSiteInfo returns almost immediately, triggering WordPressAuthenticator.fetchSiteInfo before SceneDelegate's done setting up AppCoordinator. So it's not straightforward to reproduce the crash.

The best bet is to use the debugger: add a breakpoint in the first line of DefaultStoresManager.restoreWordPressSite then do the following steps:

  1. Switch to the code before this fix.
  2. Log in to a self-hosted store with site credentials.
  3. Run the debugger with the above breakpoint.
  4. When the breakpoint pauses, check p WordPressAuthenticator.shared. You should see in Xcode console: error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x197309f0c). The process has been returned to the state before expression evaluation.
  5. Switch to the fix in this PR and repeat the steps 1-4. Confirm that you see details about the authenticator instead of the above error.

Screenshots

N/A


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@itsmeichigo itsmeichigo added this to the 23.7 milestone Dec 3, 2025
@itsmeichigo itsmeichigo added the type: crash The worst kind of bug. label Dec 3, 2025
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 23.7. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 3, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Numberpr16426-119c1fd
Version23.7
Bundle IDcom.automattic.alpha.woocommerce
Commit119c1fd
Installation URL35glrbeqoslq0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: crash The worst kind of bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants