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

First-screen snapshot

What the snapshot stores, why it holds no geometry, and how a device turns it into a screen.

The first-screen snapshot (app.baked) is your app's first screen recorded at build time, so a device can show it before any JavaScript runs. It is the native counterpart of server-rendered HTML: content the user sees immediately, which your app's code takes over later.

What it stores

StoredWhy
Your app's first commit, from the selected rendererThe exact element tree and text your first render creates
Scoped <style> sheets from your componentsSo styles that arrive with modules are in place
Each element's computed style, for light and darkNo CSS cascade on device; dark mode is ready too
Which elements depend on the viewportOnly those are restyled on device
A hash of app.hbcTies the snapshot to the bytecode it came from

It does not store positions or sizes. Text measurement differs between macOS and iOS, and between a phone and a tablet, so the snapshot is laid out on the device. That is what lets one snapshot serve every native target and every screen size.

Targets

bake build --target android,windows --bake writes one app.baked per target, next to that target's app.hbc (dist/android/app.baked, dist/windows/app.baked). Each is paired with its own bytecode by hash, and manifest.json names the target in frame.target. They are separate files because each target's bundle can render a different first screen (import.meta.env.BAKE_TARGET branches), not because the baking differs: the cascade never reads the platform, so a page without platform code bakes to the same styles for every target and lays out to the same boxes on every device, the boxes Chrome draws. Any host can bake any target (a Mac can bake android and windows, Windows can bake ios and mac).

The values that really are platform-specific are applied on the device, never baked:

ValueIn the snapshotOn the device
Default font (system-ui, -apple-system)The family name, unchangedResolved and measured with the platform's font: SF Pro on iOS and macOS, Roboto on Android, Segoe UI Variable on Windows. Name a font with @font-face for the same text everywhere.
Native controls (unstyled or .native button and text field; checkbox, switch, range, select, progress, date, color)Only the computed style and the Button / Input / Control roleLaid out at the platform's own size: AppKit, UIKit, Material 3 (button 40 dp tall, text field 56 dp) or WinUI 3 (button and field 32 px), replaced by the host's measured sizes once it reports them. Author-styled buttons and fields (controls.css, or any background, border or appearance: none) are the same box everywhere.
Dark mode colorsBoth schemes, with Chromium's system colors (canvas, canvastext, buttonface…, Chromium's defaults with no OS mapping, so Chrome on Windows and macOS can differ in light mode; see Rendering) and your light-dark() / prefers-color-scheme valuesThe device picks the scheme; native controls draw their own dark chrome.
Safe area (env(safe-area-inset-*))Baked with every inset at 0; elements that read an inset are marked to restyleRestyled with the device's insets.
Viewport, font scale, display scaleThe reference viewport only (see below)The real values.

Viewport-dependent styles

Media queries and viewport units mean an element's style can depend on the screen. While baking, BakeNative styles your tree at a set of reference sizes plus both sides of every width, height and aspect-ratio breakpoint in your media queries, in portrait and landscape, and marks every element whose style changes. On device, only those elements are restyled for the real viewport. If the page itself (html, body, the root element) depends on the viewport, the whole snapshot is restyled.

--viewport sets the reference size used for that check. It does not fix the size your screen is drawn at.

On the device

app.baked ─▶ apply the first commit ─▶ attach baked styles (light or dark)
         ─▶ restyle viewport-dependent elements ─▶ lay out with device fonts at the real size
         ─▶ draw: one pass over the rows, one native view per drawn element

The last step is deliberately simple. Rows come in tree order, parents before children, and each row carries its paint style, text and frame, so drawing is "create view, apply style, set frame, add to parent" per row. No lookups, no cascade and no layout happen while views are created.

The on-device cache

After a screen mounts without a usable snapshot, the host caches JavaScript's first commit as a snapshot of its own: a .baked v4 file with both color schemes, which later launches open like a baked app.baked. Each environment the screen opened in gets its own file, a slot. On iOS the file name carries:

  • the bundle key (the app.hbc and app.css hashes from manifest.json), combined with the root component's initial props when the host passes any (BakeNativeView(props:)); props that are not JSON are not cached, and with this build of the app and the OS (the Mach-O UUIDs of the app and of BakeNative, and the OS version), so an app or OS update never shows a screen cached by the build before it
  • the layout viewport in points
  • the display scale
  • the page's safe-area insets
  • the text size
  • the first preferred OS language, the current OS locale, and the resolved app locale. These values affect JavaScript formatting and which translations the screen renders

On Android the name carries the bundle key combined with the app install and the OS build (the APK's path and modification time, and the OS fingerprint), the view's size in device pixels, the density, the safe insets, the font scale, the process's default locale, and the resolved app locale.

A foldable's closed and open screens, or portrait and landscape, therefore each have a slot and each hit. After the device language changes, the first launch is a miss and caches the screen in the new language; it never shows the old one.

  • Miss. Looking up a size that has no slot costs a single failed open. On the simulator that is about 10 µs warm, including the file name, and about 60 µs for the first lookup in a process. The launch then draws the baked app.baked instead, or mounts from JavaScript when the bundle has none.
  • Hit. The 80-byte header is checked again: the viewport the file was committed at, and the slot key in bytes 72–79 (a hash of the same inputs as the name), on iOS and Android. A file whose header disagrees with its slot is deleted and treated as a miss. On Android the page may be shorter than the view: a header bar, which the snapshot itself brings, takes the rest, and for one slot it is the same height at every launch.
  • Rewritten. A launch whose first commit differs from the snapshot it showed writes the slot again, also when the snapshot was adopted (same structure and text, other classes, styles or attributes; a text difference remounts). A stale screen is shown at most once. A screen whose first render changes every launch (the time, a random value) is therefore written every launch.
  • Eviction. At most 8 slots are kept, and the least recently used is deleted after a write.

The color scheme is not part of the key, because one file holds both schemes. A cached file holds what the first render of the screen produced, so it lives in the app's caches directory and is deleted with it.

While the snapshot is on screen, before JavaScript takes over, a resize (unfolding, rotation, split view), a safe-area change or a switch to dark mode lays it out again in the same main-thread turn. No frame laid out for the previous size reaches the screen.

Runtime values

The rule is the one server rendering already has for hydration. The build plays the server: it renders your app's first commit, and the device hydrates it. As with a server-rendered page, the first render on the device must produce exactly what the build produced, so it may only read what the build knows.

A first render that reads the clock (Date.now(), new Date()), randomness, Intl formatting, the host's props or a native module therefore fails the build. Every such read, in every locale's bake, is listed at once, at the line that reads it:

src/Feed.tsrx:2:18: error: the first render reads Date.now() [en, ko]
    2 |   const posted = Date.now();
      |                  ^^^^^^^^^^
  in App > Feed
  fix: keep a default in state and set the real value in an effect, … (first-screen-read).

Fix it as you would a hydration mismatch. Draw the first screen with a default, and bring the real value in after it:

import { useEffect, useState } from 'octane';
import { Text } from '@bake-native/octane';

// The host's props: parameter defaults. The first screen uses them; the host's props arrive
// right after the first commit, as an update.
export function App({ name = 'there' }) @{
  // The clock: an initial value in state, the real value from an effect after the first render.
  const [year, setYear] = useState(2026);
  useEffect(() => setYear(new Date().getFullYear()), []);
  <Text>{'Hi ' + name + ' · © ' + year}</Text>
}

The root component's props are checked when you bake: every key its parameter destructures needs a default ({ name = '' }), and a key the first render reads another way (props.name) fails the build at that line.

Or make the value asynchronous and show a pending branch until it arrives. The pending branch is the first screen:

import { Text } from '@bake-native/octane';

export function Feed({ posts }) @{
  @try {
    <PostList posts={posts} />   // posts: a promise (derived$), read with use()
  } @pending {
    <Text class="loading">Loading…</Text>
  }
}

In a .tsx file the same is <Suspense fallback={<Text>Loading…</Text>}>.

On the device the first render is the same as the build's: no props, the same defaults, the same locale. So the first commit is the first screen, the screen is adopted as it is, and nothing moves. A debug core reports a first commit that differs from its first screen as an error (first-screen-mismatch).

If a screen's first render must show a runtime value, set bake: false in bake.config.ts (bake): that app has no baked first screen.

Kept honest

A snapshot is only useful if it is exactly what your app would have rendered. BakeNative enforces that:

  • A snapshot baked from a different app.hbc is never adopted.
  • If Hermes's first commit differs from the snapshot, the snapshot is replaced by a normal render (adoption).
  • A snapshot written by an incompatible version of BakeNative is refused, and the screen renders from JavaScript instead.

The byte layout is in the .baked reference.

On this page