Skip to content

Commit a8fb2a3

Browse files
authored
docs: document multi-worktree Metro workflow (#841)
1 parent d7beb52 commit a8fb2a3

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/utils/__tests__/args.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,9 @@ test('usageForCommand resolves react-native help topic', () => {
14211421
assert.match(help, /same host context that owns Metro/);
14221422
assert.match(help, /sandbox probe is not authoritative/);
14231423
assert.match(help, /adb reverse only affects Android device-to-host traffic/);
1424+
assert.match(help, /Multiple local worktrees can reuse one native iOS simulator build/);
1425+
assert.match(help, /--metro-host 127\.0\.0\.1 --metro-port 8081/);
1426+
assert.match(help, /One simulator cannot run two copies of the same bundle id/);
14241427
assert.match(help, /Keep the agent-device react-devtools prefix/);
14251428
assert.match(help, /Use help react-devtools for status\/wait/);
14261429
assert.match(help, /logs clear --restart/);

src/utils/cli-help.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ React Native dev loop:
456456
Android RN/Expo Metro: direct Android localhost URL opens with a port auto-configure host reachability. For app/package launches, use help react-native if the app cannot reach local Metro.
457457
Verify Metro from the same host context that owns Metro. If a sandboxed shell cannot curl localhost:8081/status but an unrestricted host shell can, Metro is running and the sandbox probe is not authoritative.
458458
adb reverse only affects Android device-to-host traffic. It does not prove host-to-Metro reachability, and it does not fix a redbox caused by a stale or wrong Metro/app state.
459+
Multiple local worktrees can reuse one native iOS simulator build by running each worktree's Metro on a different port and opening the same installed app on different simulators with explicit runtime hints:
460+
agent-device open "React Navigation Example" --platform ios --device "iPhone 17" --session rn-a --metro-host 127.0.0.1 --metro-port 8081 --relaunch
461+
agent-device open "React Navigation Example" --platform ios --device "iPhone 17 Pro" --session rn-b --metro-host 127.0.0.1 --metro-port 8082 --relaunch
462+
iOS simulator opens write React Native's per-simulator debug server settings before launch, so those ports do not conflict across simulators. Use separate sessions/devices, close both sessions when done, and rebuild only for native changes or dependency changes that affect the binary. One simulator cannot run two copies of the same bundle id.
459463
Expo Go/dev clients are host shells. Use provided project URLs, verify with snapshot -i after opening, and ask instead of inventing app ids or URLs. Help workflow owns the full Expo URL command shapes.
460464
461465
Overlays and busy RN UIs:

test/skillgym/suites/agent-device-smoke-suite.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,37 @@ const SKILL_GUIDANCE_CASES: Case[] = [
11991199
],
12001200
forbiddenOutputs: [/open\b.*--relaunch/i, /(?:^|\n)(?:agent-device\s+)?screenshot\b/i],
12011201
}),
1202+
makeCase({
1203+
id: 'ios-rn-two-worktrees-one-native-build',
1204+
contract: [
1205+
'App name: React Navigation Example',
1206+
'Platform: iOS simulators',
1207+
'The app is already installed on both simulators',
1208+
'Worktree A Metro is already running on 127.0.0.1:8081',
1209+
'Worktree B Metro is already running on 127.0.0.1:8082',
1210+
'Use iPhone 17 for worktree A and iPhone 17 Pro for worktree B',
1211+
'Use separate sessions rn-a and rn-b',
1212+
'Do not rebuild, reinstall, or run package manager commands',
1213+
],
1214+
task: 'Plan the agent-device commands to launch the same installed React Native iOS app against each worktree Metro instance and verify both sessions with interactive snapshots.',
1215+
outputs: [
1216+
/open\s+["']?React Navigation Example["']?(?=[^\n]*--platform ios)(?=[^\n]*--device ["']?iPhone 17["']?)(?=[^\n]*--session rn-a)(?=[^\n]*--metro-host 127\.0\.0\.1)(?=[^\n]*--metro-port 8081)(?=[^\n]*--relaunch)/i,
1217+
/open\s+["']?React Navigation Example["']?(?=[^\n]*--platform ios)(?=[^\n]*--device ["']?iPhone 17 Pro["']?)(?=[^\n]*--session rn-b)(?=[^\n]*--metro-host 127\.0\.0\.1)(?=[^\n]*--metro-port 8082)(?=[^\n]*--relaunch)/i,
1218+
/snapshot -i(?=[^\n]*--platform ios)(?=[^\n]*--session rn-a)/i,
1219+
/snapshot -i(?=[^\n]*--platform ios)(?=[^\n]*--session rn-b)/i,
1220+
],
1221+
forbiddenOutputs: [
1222+
/run-ios/i,
1223+
/reinstall/i,
1224+
/install\b/i,
1225+
/yarn|pnpm|npm|npx/i,
1226+
/adb\s+reverse/i,
1227+
/--device "iPhone 17"[^\n]*--session rn-b/i,
1228+
/--device "iPhone 17 Pro"[^\n]*--session rn-a/i,
1229+
],
1230+
strictFinalOutput: true,
1231+
allowOnlyLocalCliHelpCommands: true,
1232+
}),
12021233
makeCase({
12031234
id: 'rn-warning-overlay-dismiss-before-tap',
12041235
contract: [

website/docs/docs/commands.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,31 @@ agent-device react-devtools profile report @c5
709709
- Remote bridge React DevTools assumes the React Native-bundled DevTools behavior in React Native 0.83+. Older browser/Chromium DevTools workflows are not assumed to exist inside remote sandboxes. Expo projects should be verified against the SDK's bundled React Native version before relying on this path; this release does not claim a separately verified Expo SDK version.
710710
- For cross-platform validation with explicit target selectors, use separate sessions/devices and restart `react-devtools` between iOS and Android runs.
711711

712+
## Multiple React Native worktrees
713+
714+
You can reuse one installed iOS simulator debug build across multiple local worktrees when the native binary is compatible with both JavaScript trees. Run one Metro server per worktree on a unique port, then open the same app on different simulators with explicit Metro runtime hints:
715+
716+
```bash
717+
# Worktree A terminal
718+
yarn expo start --dev-client --port 8081 --host localhost
719+
720+
# Worktree B terminal
721+
yarn expo start --dev-client --port 8082 --host localhost
722+
723+
agent-device open "React Navigation Example" --platform ios --device "iPhone 17" --session rn-a --metro-host 127.0.0.1 --metro-port 8081 --relaunch
724+
agent-device open "React Navigation Example" --platform ios --device "iPhone 17 Pro" --session rn-b --metro-host 127.0.0.1 --metro-port 8082 --relaunch
725+
```
726+
727+
- Use different simulators and sessions for each worktree. One simulator cannot run two copies of the same bundle id at the same time.
728+
- On iOS simulators, `open` writes React Native's per-simulator debug server settings before launching, so `rn-a` can use port `8081` while `rn-b` uses port `8082`.
729+
- This covers JavaScript and Metro-resolved workspace changes. Rebuild/reinstall the app when native code, native dependencies, bundle identifiers, entitlements, or generated native project files change.
730+
- Close every manually opened session when done:
731+
732+
```bash
733+
agent-device close --platform ios --session rn-a
734+
agent-device close --platform ios --session rn-b
735+
```
736+
712737
## Metro reload
713738

714739
```bash

0 commit comments

Comments
 (0)