#1102·tolaria

Mobile app (`apps/mobile`) traps at launch on a physical iPad — `RCTKeyCommands` is simulator-only

Author: artcashinCreated Aug 3, 2026Updated Sep 26, 2026

Summary

TolariaKeyCommandsModule.registerCommands() calls RCTKeyCommands.sharedInstance(), but React Native compiles that class out on real hardware. The fallback returns nil, Swift imports it implicitly unwrapped, and calling through it traps the process before any UI appears.

This affects any physical iOS/iPadOS device, in Debug as well as Release. It cannot reproduce on the simulator, which is where the native keyboard shortcuts were developed and verified.

Environment

  • Branch: mobile-ui-foundation @ d38a9905
  • @tolaria/mobile 0.1.0 — Expo ~54.0.35, React Native 0.81.5
  • Device: iPad Pro 11-inch (M5) (iPad17,2), iPadOS 26.6 (23G71)
  • Built with Xcode 26.6, -configuration Release, installed via devicectl

Steps to reproduce

  1. Build apps/mobile for an attached physical iPad (any configuration).
  2. Install and launch it.

The app terminates within about a second. It never renders.

Expected

The app launches. On hardware that lacks the native key-command API, shortcuts are simply unavailable.

Actual

EXC_BREAKPOINT / SIGTRAP on com.apple.main-thread. Crash report top frame:

0  TolariaMobile  closure #1 in TolariaKeyCommandsModule.registerCommands()
1  TolariaMobile  <deduplicated_symbol>
2  libdispatch    _dispatch_call_block_and_release
...
13 TolariaMobile  main

Cause

react-native/React/Base/RCTKeyCommands.m:17 gates the entire implementation:

objc
#if RCT_DEV && (TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST)

Outside that guard the fallback is:

objc
+ (instancetype)sharedInstance
{
  return nil;
}

TARGET_OS_SIMULATOR is 0 on a device, so sharedInstance returns nil regardless of RCT_DEV. The header declares + (instancetype)sharedInstance with no nullability annotation, so Swift imports it as RCTKeyCommands! and the first call in the runOnMain block is a forced unwrap of nil — a runtime trap rather than a soft failure.

Suggested fix

Bind the optional in apps/mobile/modules/tolaria-key-commands/ios/TolariaKeyCommandsModule.swift, in both registerCommands() and unregisterCommands():

swift
guard let keyCommands = RCTKeyCommands.sharedInstance() else { return }

for command in self.commands {
  keyCommands.registerKeyCommand(
    withInput: command.input,
    modifierFlags: command.modifierFlags
  ) { [weak self] _ in
    self?.sendShortcut(command)
  }
}

That turns the crash into shortcuts that are inert off the simulator, leaving the existing simulator behaviour and the keyboard-shortcut proof tests unchanged. Making the shortcuts actually work on a device is separate work — it needs UIKeyCommand on a UIResponder, not this API.

Note on a regression test

AGENTS.md asks for a failing regression test first, and I could not write an honest one. The crash only occurs where RCTKeyCommands is compiled out, so neither the simulator nor CI can reproduce it — a test asserting the fixed behaviour would pass before and after the change. Happy to add one if you see an angle I missed, e.g. asserting isSupported/registration state on a device-shaped build.

I have the fix on a branch and can open a PR against mobile-ui-foundation if that is the branch you want it on — apps/ does not exist on main, so there is nowhere else for it to go.