|
| 1 | +# React DevTools Commands |
| 2 | + |
| 3 | +All commands are run through `agent-device react-devtools`. |
| 4 | + |
| 5 | +## Connection |
| 6 | + |
| 7 | +```bash |
| 8 | +agent-device react-devtools start |
| 9 | +agent-device react-devtools stop |
| 10 | +agent-device react-devtools status |
| 11 | +agent-device react-devtools wait --connected --timeout 30 |
| 12 | +agent-device react-devtools wait --component <ComponentName> --timeout 30 |
| 13 | +``` |
| 14 | + |
| 15 | +- `status` shows the daemon port, connected apps, component count, profiling state, uptime, and last connection event. |
| 16 | +- Most commands auto-start the daemon, but `start` is useful before launching or reloading the app. |
| 17 | +- React Native development builds connect to the daemon on port 8097. For Android emulators or physical devices, use `adb reverse tcp:8097 tcp:8097` if the app cannot reach the host. If the app also uses local Metro, set `adb reverse tcp:8081 tcp:8081`. |
| 18 | + |
| 19 | +## Validation Notes |
| 20 | + |
| 21 | +- When validating the same app across iOS and Android with explicit `--device`, `--udid`, or `--serial` selectors, prefer an isolated `--state-dir` over separate named sessions. A named `--session` enables bound-session lock behavior, so setup commands with explicit target selectors can be rejected. |
| 22 | +- Restart the React DevTools daemon between platforms so `status`, `get tree`, and profiling output belong to the currently launched app. |
| 23 | +- Verify the app is visibly loaded with `snapshot` before collecting React internals. Use `react-devtools` for component state and profiling, not for proving the device/app surface is open. |
| 24 | + |
| 25 | +## Component Inspection |
| 26 | + |
| 27 | +```bash |
| 28 | +agent-device react-devtools get tree --depth 3 |
| 29 | +agent-device react-devtools get component @c5 |
| 30 | +agent-device react-devtools find Button |
| 31 | +agent-device react-devtools find Button --exact |
| 32 | +agent-device react-devtools count |
| 33 | +agent-device react-devtools errors |
| 34 | +``` |
| 35 | + |
| 36 | +- `get tree` prints a component hierarchy with labels like `@c1`, `@c2`. |
| 37 | +- Use `--depth` on large apps. Start at `--depth 3` or `--depth 4`. |
| 38 | +- `get component` accepts a label or numeric React fiber id and shows props, state, and hooks. |
| 39 | +- `find` searches by display name. Use `--exact` when fuzzy results are noisy. |
| 40 | +- `errors` lists components with React-tracked warnings or errors. |
| 41 | + |
| 42 | +## Profiling |
| 43 | + |
| 44 | +```bash |
| 45 | +agent-device react-devtools profile start "interaction name" |
| 46 | +agent-device react-devtools profile stop |
| 47 | +agent-device react-devtools profile slow --limit 5 |
| 48 | +agent-device react-devtools profile rerenders --limit 5 |
| 49 | +agent-device react-devtools profile report @c5 |
| 50 | +agent-device react-devtools profile timeline --limit 20 |
| 51 | +agent-device react-devtools profile commit 3 |
| 52 | +agent-device react-devtools profile export profile.json |
| 53 | +agent-device react-devtools profile diff before.json after.json --limit 10 |
| 54 | +``` |
| 55 | + |
| 56 | +- `profile slow` ranks components by average render duration. |
| 57 | +- `profile rerenders` ranks components by render count. |
| 58 | +- `profile report @cN` shows render causes and changed props/state/hooks for one component. |
| 59 | +- `profile timeline` lists commits. Use `--limit` and `--offset` for long sessions. |
| 60 | +- `profile export` writes React DevTools Profiler JSON that can be diffed later. |
| 61 | + |
| 62 | +## Common Flows |
| 63 | + |
| 64 | +Inspect a component: |
| 65 | + |
| 66 | +```bash |
| 67 | +agent-device react-devtools status |
| 68 | +agent-device react-devtools get tree --depth 3 |
| 69 | +agent-device react-devtools find SearchScreen |
| 70 | +agent-device react-devtools get component @c12 |
| 71 | +``` |
| 72 | + |
| 73 | +Profile a slow interaction: |
| 74 | + |
| 75 | +```bash |
| 76 | +agent-device react-devtools profile start "slow search" |
| 77 | +# Trigger the interaction with agent-device or ask the user to perform it. |
| 78 | +agent-device react-devtools profile stop |
| 79 | +agent-device react-devtools profile slow --limit 5 |
| 80 | +agent-device react-devtools profile rerenders --limit 5 |
| 81 | +``` |
| 82 | + |
| 83 | +Verify a render fix: |
| 84 | + |
| 85 | +```bash |
| 86 | +agent-device react-devtools profile start "after fix" |
| 87 | +# Repeat the same interaction. |
| 88 | +agent-device react-devtools profile stop |
| 89 | +agent-device react-devtools profile slow --limit 5 |
| 90 | +agent-device react-devtools profile rerenders --limit 5 |
| 91 | +``` |
0 commit comments