Skip to Content
Octapus

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)
StrategyTakes over the screenGood for
.load (default)Right after the snapshot is on screenMost screens
.idleWhen the main thread is next idleScreens shown during a busy transition
.interactionOn the first tap or keystroke; that input is then delivered to your appScreens users often only look at
.neverNot automatically; call root.hydrate() yourselfStatic screens, previews, your own trigger
.after(milliseconds:)After a fixed delayMeasuring 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.

On this page