Hot Reload
pam dev builds and installs the debug app once, then keeps a sync server running.
When you save a file, only the changed files travel to the device and PHP restarts
inside the same app process. Navigation is restored and #[State] properties keep
their values, so you see the change in place instead of starting over.
Hot reload covers everything that ships in the PHP bundle: components (.pam,
.pam.php, PHP classes), styles, assets, and vendor/ after a Composer update.
Start a session
Section titled “Start a session”pam devpam ios:devKeep one session per app. The terminal reports every step:
Android sync: indexed 2108 files (16.8 MiB) in 464 ms; the device fetches only files it does not holdAndroid change e7a2501762af: 1 file changed (src/Components/Inbox/InboxHeader.pam.php), 8.0 KiB to send, indexed in 42 msAndroid sync: sent 1 file (8.0 KiB) in 0 msAndroid reload e7a2501762af: screen updated in 305 ms, 1 file (8.0 KiB) applied; change to screen 531 msscreen updated is measured on the device, from receiving the new version to the
first committed frame. change to screen adds indexing and transfer, from the
moment the CLI saw your save.
What survives a reload
Section titled “What survives a reload”- Navigation is restored as on any restart (persisted navigators and restorable components).
- Component state survives: just before the old PHP request shuts down, the
#[State]properties of every mounted component are recorded by position in the tree. A component of the same class at the same position gets them back before itsmount()runs.
What does not survive: props, services, objects and plain fields. A structural
edit above a component, a renamed class, or a value the new property type rejects
makes that component start fresh. Snapshots expire after 5 seconds, so a cold
start never restores development state, and App::reload() always behaves like a
cold start.
use Pam\Native\Attributes\State;use Pam\Native\Component;
final class Filters extends Component{ #[State] public string $selected = 'all'; // kept across hot reloads
public array $results = []; // reset on every reload}How the sync works
Section titled “How the sync works”- The CLI indexes the project (the same files a build would bundle) into a manifest
of digests. Unchanged files are never read twice, and
vendor/is re-indexed only whenvendor/composer/installed.jsonchanges. - The device long-polls the CLI. The first sync downloads only the files the device does not already hold, reusing those from the installed app.
- Each save arrives in the same long-poll response: the new version, a delta and the edited files.
- The device writes into a stable tree, shuts the previous PHP request down, swaps the files in and starts the next request. Stable paths keep OPcache and the component cache warm, so only edited files recompile.
There is no size limit: large apps with thousands of files sync the same way as small ones.
When a reload fails
Section titled “When a reload fails”Saving a syntax error or code that throws opens the error overlay
without closing the app, and the terminal prints … failed after N ms. Fix the
file and save again; the overlay clears and the fixed code renders.
When you must restart
Section titled “When you must restart”Hot reload swaps PHP. It cannot change the native host. Stop pam dev with
Ctrl+C and start it again after you:
- add or remove a plugin (
pam composer require …); - change permissions, deep links, icons or anything else in
pam-native.json; - add a native module or native view.
The CLI prints a note when one of those files changes.
Devices and ports
Section titled “Devices and ports”Each app uses its own device port between 39100 and 39899, derived from its debug
package name, so two apps on one phone never reach each other’s server. adb reverse maps that port to the same port on your machine. It works the same over
USB and over wireless debugging.
| Setting | Effect |
|---|---|
ANDROID_SERIAL |
The device to use when several are connected. Without it, pam dev stops and lists them. |
PAM_NATIVE_ANDROID_DEV_PORT |
A different host port (1024–65535) for this session. |
PAM_NATIVE_DEV_NO_ADB=1 |
Skip adb entirely; you provide the connection. |
If the cable is replugged, the adb server restarts or Wi-Fi reconnects, the CLI notices within a few seconds and restores the mapping; the app reconnects by itself. PAM only ever adds its own mapping: if another session already maps the port elsewhere, it reports the conflict instead of taking it over.
When pam dev ends (Ctrl+C, a crash, or the terminal closing), PAM first stops the
app, so it stops reconnecting, then removes only the mapping this session created.
It never removes other mappings or disconnects devices.
Reconnect without rebuilding
Section titled “Reconnect without rebuilding”If the debug app is still installed and you only lost the terminal, start the sync server alone, without a Gradle build or reinstall:
pam native dev:serveVerify interactions after a reload
Section titled “Verify interactions after a reload”When you work on the development pipeline itself, check more than the redraw:
- increment a counter;
- edit the component source and wait for the reload;
- press the same button again and confirm the count continues;
- navigate forward and press Back;
- open and dismiss a sheet or modal.
This catches a screen that redraws while its events still point at the old runtime.