BakeNative is under active development. APIs may change.
Skip to Content
BakeNative

Launch overview

The path from React or Octane source to a native screen that appears before JavaScript runs.

Native apps built on a JavaScript runtime usually start the same way: launch the app, start the JS engine, run the bundle, render, create every view, and only then show something. BakeNative moves most of that work out of the launch.

Three stages

1. Build

bake build compiles your app from the same source for each selected target:

  • For web, a normal browser build that renders to the DOM.
  • For each native target, a single script that renders through the selected adapter, compiled by hermesc into Hermes bytecode (app.hbc). Branches on import.meta.env.BAKE_TARGET for other platforms are removed.

2. Bake

A native React build, or an Octane build requesting a bake, runs your bytecode once in Hermes, takes the first commit (the element tree your app renders on its first pass), resolves its CSS for light and dark mode, and writes the result as the first-screen snapshot (app.baked). The snapshot holds no positions or sizes, because those depend on the device.

3. Launch

The host lays out the snapshot at the view's real size and draws it as native views. After the first frame commits, Hermes loads app.hbc on the host's main thread and renders your app's first commit.

When the hydration strategy says so, BakeNative compares Hermes's first commit with the snapshot. If they describe the same tree, it hands the views already on screen to your app instead of creating new ones (adoption). From then on, your app updates those views like any other render.

1 · BUILD2 · LAUNCH3 · HYDRATIONtimesrc/App.tsrxbake build --bakehermesc → app.hbcruns app.hbc once in Hermesrecords the first commitapp.bakedthe first commitits styles, light and darkno positions or sizesapp.hbcyour app as bytecodeMain threadLay out app.bakedRust core, real size,device fontsSnapshot on screennative views, no JStaps are heldAdoptedsame views, now live0 views createdheld taps deliveredStart Hermesload app.hbcafter the first frameFirst renderthe app’s first commitsame tree?yes → adoptNo: remountsnapshot dropped,first commit mountedas new viewswhen the hydration strategy fires (load, idle, interaction)

Brownfield first paint

When a tap in an existing native app opens a BakeNative screen, the destination's first visible frame should already contain the screen's content. Measure the time from the tap to that frame. Keep content visible throughout the transition and while the runtime takes over. A white or background-only placeholder frame counts as a regression.

BakeNative commits the baked first screen before starting Hermes. When the trees match, the runtime adopts the native views already on screen. After adoption, the renderer sends committed changes to BakeNative. The core reuses cached style and layout where it can, and the host reuses the existing views to apply the changes the update requires.

Verify first paint with a Release build on a physical Android device. Compare cache hits and misses separately. Use the device's displayed frames to check for blank frames, and measure runtime adoption and subsequent update costs separately from tap-to-content. See Brownfield for how to embed a screen.

Why it is fast

  • Nothing to compute at first paint. Your CSS was resolved at build time, and drawing the snapshot is one forward pass over its rows.
  • JavaScript is off the critical path. It runs in parallel with the first paint instead of before it.
  • No second build of the screen. Adoption reuses the views that are already visible, so the takeover costs milliseconds and nothing flickers.

Use built-in views first

Build each screen from your adapter's built-in native views whenever one can express the UI. Both adapters export these built-in views from their root import.

PurposeReact (@bake-native/react)Octane (@bake-native/octane)
ContainerViewView
TextTextText
ImageImageImage
Long list of fixed-height rowsListVirtualList
Press targetPressableNo built-in view. Use <button onClick>.

For controls such as buttons, inputs and checkboxes, use the supported HTML element (see HTML also works). Use Native UI (@bake-native/react/ui, with platform packages such as ui/swift-ui) only when a part of the screen needs the platform's own UI toolkit, for example a SwiftUI control and its system look.

Why built-in views come first

On native targets, View and Text render as their own host kinds, bake-container and bake-text, instead of div and span. The core and the hosts give these kinds update paths that a general element does not get:

  • When an inline opacity is the only change to a View, the core patches that value instead of restyling the element. The iOS, macOS, Android, and Windows hosts then change only the view's opacity, with no repaint. The path does not apply in some cases, for example when the opacity reaches 0 or crosses 1, when the View holds text directly, or while a transition or animation runs on it.
  • On iOS, when only the content of a Text changes, the host can replace the text runs of the existing label instead of configuring the whole view again. The core still measures and lays out the new text.

More update paths will use these host kinds as they land. Every other change to a View or a Text takes the same restyle and layout path as the matching HTML element. An update that changes only an inline transform has its own path on every element, built-in or HTML.

The other built-in views give you an API rather than an update path. Image takes source and resizeMode and draws through the same image view as <img>. Pressable renders a button with onPress, disabled, and accessibility props. List and VirtualList render only the rows near the visible part of the list, and the native host recycles their rows as you scroll (Long lists). React's built-in views also reject a prop they do not support, and the error names a supported alternative.

HTML also works

Supported HTML elements (div, p, span, button, img, and the rest of the support list) and CSS render on every native target. The shared Rust core styles and lays them out, and each host draws them as platform views. HTML elements and built-in views share one element tree, one baked first frame, and one adoption path, so a screen can mix them.

HTML is the path for existing web markup and for HTML-based component libraries. Build a reused component for each native target before you ship it. bake build rejects unsupported markup, CSS, and browser APIs, and reports the source location and a supported alternative. If a component depends on behavior that only a browser has, keep it on the web behind a platform branch and use a built-in view on native targets.

Which one to use

UseWhenYou gainYou give up
A built-in viewNew screens, and any container, label, image, press target, or long list that a built-in view coversThe View opacity path, the Text runs path on iOS, row recycling in lists, and props that the adapter checksThe props that the built-in view does not accept. Octane's View and Text take no event handlers and no ref.
An HTML elementExisting web markup, HTML-based component libraries, and elements that have no built-in view, such as <input>, <dialog>, <svg>, and <video>The same markup and CSS on the web and on native targets, and every element in the support listThe update paths of View and Text. Each change takes the general restyle and layout path.

See Rendering for how the shared core draws both.

On this page