$npx -y skills add skydoves/compose-performance-skills --skill preserving-state-across-reloadsUse this skill to keep Jetpack Compose state alive across HotSwan hot reloads by understanding the three escalating tiers Compose HotSwan uses (tier 1 targeted recomposition, tier 2 composition reset, tier 3 Activity.recreate) and choosing edits and state holders that stay inside
| 1 | # Preserving State Across Reloads: keep edits inside HotSwan tier 1 |
| 2 | |
| 3 | Compose HotSwan applies every hot reload through three escalating tiers. Tier 1 (targeted recomposition) preserves the most: scroll position, navigation back stack, `remember` and `rememberSaveable` values, `ViewModel` state, lazy layout items, dialog and bottom sheet state. Tier 2 (composition reset) disposes and recreates compositions, dropping per-composable `remember`. Tier 3 (`Activity.recreate()`) restarts the Activity and only state held by `ViewModel` or `SavedInstanceState` survives. |
| 4 | |
| 5 | The iteration loop is fastest and least surprising when every reload stays inside tier 1. This skill covers which edits trigger which tier, which state holders survive each tier, and how to hoist transient UI state when an edit must escalate. |
| 6 | |
| 7 | ## When to use this skill |
| 8 | |
| 9 | - The developer reports "scroll jumped to top after a hot reload", "lost dialog state", "lazy column re-fetched", or "tab selection reset to zero". |
| 10 | - The developer is about to refactor a composable and wants to know which recomposition scope the change touches. |
| 11 | - The HotSwan tool window status shows a tier 2 or tier 3 reload and the developer wants to understand why it escalated. |
| 12 | - The developer asks which state holders survive `Activity.recreate()` versus a composition reset. |
| 13 | - The user mentions "tier 1", "tier 2", "tier 3", "composition reset", "HotSwan state preservation", or "rememberSaveable across reload". |
| 14 | |
| 15 | ## When NOT to use this skill |
| 16 | |
| 17 | - The change was rejected as a schema violation entirely (added a parameter, changed a constructor, added a new resource ID) and HotSwan fell back to a full incremental build. See `../understanding-hot-reload-limits/SKILL.md`. |
| 18 | - HotSwan is not installed or the watcher is not running. See `../setting-up-compose-hotswan/SKILL.md`. |
| 19 | - The developer wants an AI agent to drive the loop autonomously. See `../iterating-with-ai-and-mcp/SKILL.md`. |
| 20 | - The recomposition itself is too wide independent of hot reload (a parent invalidating a whole subtree on every state tick). Diagnose with `../../recomposition/debugging-recompositions/SKILL.md` first. |
| 21 | |
| 22 | ## Prerequisites |
| 23 | |
| 24 | - Compose HotSwan installed and `WATCHING` against the running app. Setup lives in `../setting-up-compose-hotswan/SKILL.md`. |
| 25 | - Familiarity with Compose recomposition scopes; cross-link `../../recomposition/debugging-recompositions/SKILL.md` for the underlying mechanics. |
| 26 | - Familiarity with `rememberSaveable` for state that must survive process death and (in this context) composition reset. |
| 27 | |
| 28 | ## The three tiers |
| 29 | |
| 30 | | Tier | Mechanism | Preserves | Loses | Triggered when | |
| 31 | |---|---|---|---|---| |
| 32 | | 1. Targeted recomposition | recomposes only the affected scopes in place | navigation back stack, scroll position, `remember`, `rememberSaveable`, `ViewModel`, lazy layout items, dialog and bottom sheet state | nothing | simple body change inside one composable scope | |
| 33 | | 2. Composition reset | dispose and recreate all compositions from scratch | Activity, `ViewModel`, navigation (via `NavController`), `rememberSaveable` (depends on retention) | per-composable `remember` values not retained by a `Saveable`, scroll position not held by a saveable state holder | tier 1 unavailable (theme change, root-scope structural change) | |
| 34 | | 3. `Activity.recreate()` | recreate the entire Activity | `ViewModel`, `SavedInstanceState` | scroll, transient dialog state, anything not saved | composition fails or schema mismatch detected | |
| 35 | |
| 36 | The tier that ran is reported in the HotSwan tool window status after every reload. Read it after each edit to confirm the loop stayed where it was supposed to. |
| 37 | |
| 38 | ## Workflow |
| 39 | |
| 40 | ### 1. Read the tier from the tool window after every reload |
| 41 | |
| 42 | The HotSwan tool window prints the tier (1, 2, or 3) for each reload. If the developer expected tier 1 and the sta |