Choosing when to hydrate
Decide when JavaScript takes over the first screen, and what happens to taps that arrive before it does.
The first screen is drawn from the snapshot without JavaScript. Hydration is the moment your app's JavaScript takes over that screen and it becomes interactive. You choose when that happens with HydrationStrategy, passed to any Octapus view:
OctapusViewController(bundle: bundle, hydration: .idle)| Strategy | Takes over the screen | Good for |
|---|---|---|
.load (default) | Right after the snapshot is on screen | Most screens |
.idle | When the main thread is next idle | Screens shown during a busy transition |
.interaction | On the first tap or keystroke; that input is then delivered to your app | Screens users often only look at |
.never | Not automatically; call root.hydrate() yourself | Static screens, previews, your own trigger |
.after(milliseconds:) | After a fixed delay | Measuring and testing |
The names follow Octane's <Hydrate when={…}> strategies. Octane applies them to one part of a page; Octapus applies them to the whole screen.
JavaScript starts right away
The strategy decides when the takeover happens, not when JavaScript starts. As soon as the view launches, Hermes loads your bundle and renders on a background thread while the snapshot is being drawn. By the time the strategy fires, the first render is usually ready and the takeover takes a few milliseconds. Only .never also postpones the JavaScript work.
Taps before JavaScript is ready
Users can tap the snapshot before hydration. Those taps are not lost: Octapus holds them, and once your app has taken over the screen it delivers each one to the element that was tapped, in order. With .interaction, the first tap is what starts hydration.
Octapus drops held input instead of replaying it when it cannot be sure it lands on the same element:
- the snapshot was built from a different bundle,
- your app's first render did not match the snapshot (the screen is rebuilt), or
- hydration failed.
Measuring it
The launch metrics show the effect of each strategy:
if case .metrics(let m) = event {
print(m.phase, // .frame → .hydrating → .adopted
m.hydrationDelayMs, // snapshot on screen → takeover requested
m.jsReadyMs, // launch → first render ready
m.frameToInteractiveMs, // snapshot on screen → interactive
m.buffered, m.replayed) // taps held / delivered
}The Swift API reference lists every field.