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

Architecture

The whole system on one page, from app source to pixels on web, iOS, macOS, Android and Windows.

BakeNative has three parts. The React or Octane adapter turns the app’s committed changes into a renderer-independent batch. One Rust core turns what it renders into laid-out, painted boxes. A thin host per platform shows those boxes as native views. The build adds a fourth part: it records your first screen ahead of time, so a device can show it before JavaScript runs, and JavaScript then takes over the views already on screen.

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)
  1. Build. bake build --bake compiles the app to Hermes bytecode (app.hbc), runs it once and records its first commit with its styles as app.baked.
  2. Launch. The main thread lays out app.baked with the Rust core and draws the native views. After the first frame commits, the main thread starts Hermes.
  3. Hydration. When the hydration strategy fires, the core compares the first commit with the snapshot. If they are the same tree, your app takes over the views on screen and none are created (adoption). If not, the snapshot is replaced by a normal render.

The layers

LayerWhere it livesWhat it does
Your appsrc/App.tsx (React) or src/App.tsrx (Octane), src/styles.cssComponents and styles. The same source builds for every target
bake buildpackages/coreBundles the selected renderer with Vite, checks every native input, compiles to Hermes bytecode, bakes the first screen
JS runtimeHermes, one runtime per BakeNative viewRuns app.hbc with the selected adapter and sends each commit to the core as a binary batch
Rust corenative/rustCSS, layout, line breaking, paint, SVG, events, focus, accessibility, the first screen and adoption. The same code on every native target
Hostnative/uikit, native/appkit, native/android, native/rust/crates/bake-host-windowsCreates and updates platform views from the core's op buffer, draws text and paint, and sends input back

On the web, none of this runs: dist/web is an ordinary Vite site and the browser does styling, layout and painting.

From source to bundle

bake build compiles your app once per target from the same source (CLI).

  • Web. A normal Vite build that renders to the DOM.
  • Native (ios, mac, android, windows). One script per target that renders through the selected native renderer. import.meta.env.BAKE_TARGET is a constant, so branches for other platforms are removed. hermesc compiles the script to app.hbc.

Each native target gets its own folder:

FileWhat it is
app.hbcYour app as Hermes bytecode. There is no parse or compile step at launch
app.cssThe app's stylesheet, read by the core
app.bakedThe first-screen snapshot, with --bake
manifest.jsonHashes that pair app.hbc with app.baked, and what the bundle requires from the runtime and its native modules (manifest)

Fail-closed checks

A native target supports a subset of the web platform. Everything outside it is a build error, not a silent difference on the device. bake build checks each native bundle against two allow lists:

  • packages/core/native-support.json: elements, attributes, event handlers and JavaScript globals.
  • The Rust CSS lint (bake-css-lint, native/rust/crates/bake-css): CSS properties, values and selectors, with the same parser the core uses.

Each error names the file, the line, why the input is not supported and what to use instead. The support list is generated from the same two lists. // bake-allow <id> on a line accepts one finding when you know the difference is harmless (Writing your app).

The AOT fast path

Octane's compiler turns templates into template programs: static host plans that the runtime mounts in one step, with per-binding patchers for the parts that change. Some template shapes leave that path, for example a @for without a key, a class built from data, or a signal read during render. They still work, but the runtime takes a slower, generic path.

bake build reads every .tsrx file with OXC (the parser Octane's compiler runs on) and reports each such site, with the fix. Strict AOT is the default: every finding is an error and the build stops before it writes a target. To keep one site, add // bake-allow <rule> -- <reason>. To turn strict AOT off for the app, pass --no-strict-aot or set "bakenative": { "strictAot": false } in package.json; findings are then warnings. bake aot runs the check alone. The rules are in the CLI reference.

Baking the first screen

With --bake, bake build runs app.hbc once in Hermes on the build machine and records your app's first commit (the element tree of its first render). The bake records the prepared render before Octane runs ref callbacks or effects. It resolves the CSS of that tree for light and dark mode and writes the result to app.baked.

A requested bake must fail if the first render throws or produces no first commit. The diagnostic should identify the failing target, the app source when available, and what prevented the first render. For values that only exist at runtime, give the first render a deterministic value and apply the real value as a later update. See Keep the first render deterministic.

The snapshot holds no positions or sizes. Fonts, screen size, safe-area insets and native control sizes differ per device, so the device lays the snapshot out at launch. The cascade does not read the platform, so a page without platform code bakes to the same styles for every target.

Elements whose style depends on the viewport (media queries, viewport units) are marked during the bake. On the device only those are restyled. See First-screen snapshot for what is stored and .baked reference for the byte layout.

Launch: snapshot, then adoption

  1. The core reads app.baked and lays it out at the view's real size with the platform's fonts. The host draws it on the main thread.
  2. After the host commits that frame, Hermes loads app.hbc on the main thread and your app renders its first commit.

When the hydration strategy fires, the core compares that first commit with the snapshot. If both describe the same tree, it hands the views already on screen to your app and creates none (adoption). Taps on the snapshot that arrived before adoption are delivered to the matching elements. If the trees differ, the snapshot is dropped and the first commit is mounted from scratch. A snapshot baked from a different app.hbc is never adopted. See Hydration and adoption.

Without --bake there is no snapshot, and the first screen appears after the first commit.

Run time: JS → core → host

Hermes (JS thread)          Rust core                         Host (main thread)
  Host commit   ── batch ─▶  restyle, lay out, paint  ── ops ─▶  create / update views
                 ◀─ events ─  DOM events, focus, a11y   ◀─ events ─  touch, keys, scroll, resize
  • JS → core. The host runtime (packages/core/host-runtime.js) accepts committed host mutations from both adapters. React uses React’s reconciler to generate updates, and Octane uses its universal renderer. Each commit becomes one binary batch (the OCB2 stream, native/rust/schema/batch.oschema). The runtime refuses a bundle built for a different batch format (batchDigest in manifest.json).
  • Core. bake-core applies the batch to its document, restyles with bake-css, lays out with bake-layout (block, flex and grid), breaks lines with bake-text and builds paint records. It also routes DOM events along their capture and bubble path, tracks focus and keeps the accessibility tree.
  • Core → host. The core writes an op buffer: what changed in the view tree, with frames, paint, text runs and accessibility roles. Hosts read it with code generated from one schema (native/rust/schema/host.oschema) for Rust, Swift, Kotlin and C. A host built against a different schema is refused when the root opens.
  • Host → core. Input, scrolling, text field edits, control changes, resizes and color scheme changes go back as an event buffer.

Layout and paint are computed once, in the core, and the result is the same on every native target: Chrome is the reference that parity tests compare against (Testing). The host contributes only what the platform must: text shaping and glyph drawing, real text fields and native form controls, scrolling, input, the device's fonts and color scheme, and the platform accessibility API. See Rendering for what each platform does.

Hosts

Every host is thin: it creates a view for each box the core asks for, applies frames and paint, and forwards input.

HostViewsTextAccessibility
iOSUIKit views, Core AnimationCoreTextUIAccessibility
macOSAppKit views, Core AnimationCoreTextNSAccessibility
AndroidAndroid views, CanvasMinikin shaping, ICU line breaksAndroid accessibility
WindowsDirectComposition visuals in a child HWND, Direct2DDirectWriteUI Automation

Each host is one view you embed in an existing app: BakeNativeView / BakeNativeViewController (UIKit) or BakeNativeSurface (SwiftUI) on iOS, BakeNativeView (AppKit) or BakeNativeSurface (SwiftUI) on macOS, and BakeNativeView on Android and Windows. See the guides for iOS, macOS, Android and Windows.

Native modules

Native code reaches JavaScript as JSI host functions under globalThis.native.<Module>.<member>. JS calls them directly, with no message bus. Async functions return a Promise. A module is declared once as a TypeScript spec (<Name>.native.ts); each host implements the contract generated from it.

PlatformLanguageImplemented as
iOS, macOSSwifta class conforming to the generated <Name>Spec protocol (async throws for async members)
AndroidKotlina class extending the generated <Name>Spec abstract class (suspend fun for async members)
WindowsRusta type implementing the generated <Name>Spec trait

Modules are registered per root and installed before the bundle runs, so each view's runtime sees only its own modules. The first-party modules (Clipboard, Linking, Share) are build units of their own: SwiftPM products, Gradle projects and cargo features. bake build records the ones the bundle calls in requires.modules, and generates the registration that links exactly those (BakeNativeAppModules, System modules), so an app does not carry a module it does not use. bake native types writes the TypeScript declarations from the specs in native/<name>/ (--schema adds the modules of a schema a host wrote for modules that have no spec). A module can also send events to JS: the spec declares onX(listener): Unsubscribe and each contract gets an emitter (Events). Native calls are not available during the bake: do not call them during render. See Native modules.

App packages and OTA compatibility

An app package is one BakeNative app as a native library: its bundle, its first screen and its own native modules. A host app links the shared runtime once and any number of packages next to it (App packages). bake package builds them for iOS (<App>.xcframework); Android packages (.aar) are planned.

JS bundles can ship over the air; native code ships only with an app release. Whether a downloaded bundle may run is decided item by item:

  • The bundle's manifest.json lists what it requires: the renderer ops, events and CSS properties it uses, and the signature of each native function it calls.
  • The runtime and the package list what they provide.
  • The bundle runs when every requirement is provided with the same shape (requires ⊆ provides). Otherwise the device refuses it with the reasons and runs the package's embedded bundle.

So adding a native function or changing native code behind the same signature does not break existing bundles. Removing or reshaping something a bundle uses does. bake release check runs the same comparison in CI before an OTA release.

What is not supported

  • Anything outside the allow lists is a build error on native targets, never a fallback. The support list shows each item per target.
  • Some features differ between hosts (for example a few CSS effects on Android). Those are build errors on the targets that lack them, listed in the support list's first table.
  • Native calls during render are not supported, because the bake has no native modules.

On this page