Files
orca/mobile/scripts
Jinwoo-H 5a5caafd07 fix(mobile): keep AsyncStorage out of the WebView document, and prove it
The 13 KB the bundle grew is not esbuild's lazy `__esm` wrappers and not a cycle: there
are none of either. It is a dependency that rode in. `text-scaling` reached
`storage/preferences` for the text-scale presets, and that module imports AsyncStorage, so
the phone's document carried AsyncStorage, `merge-options` and `is-plain-obj` — 11.6 KB of
storage library inside a string with nothing to store, wrapped in esbuild's CommonJS
interop. The old generator hid this: it substituted the presets as a JSON literal, so the
import never reached the emitted text.

The presets move to `terminal/terminal-text-scales.ts`, a leaf with no imports of its own,
which `storage/preferences` imports and re-exports for the settings screen. The bundle:

  113,442 characters, 3,465 lines, 47 inputs, none from node_modules
  was 120,217 characters with 6 node_modules inputs and three `__commonJS` wrappers
  the golden it replaces was 110,085 bytes

`minify: false` stays, for the reason given: the overlay reports the line and column
`window.onerror` hands it.

Three cases join the bundle evaluation, and each was made to fail before it was kept:

- A `set-theme` and a `write` before `init`, which is what a byte golden covered by
  accident. Read from the router rather than assumed: the theme applies to the scope and
  paints through the seam, the chunk normalises and queues, the pump returns because there
  is no terminal, and `init` then resets the queue and the mode scan so the early chunk is
  dropped and the init frame's own theme wins. Deleting `resetWriteQueue` from `init` makes
  the terminal write `early chunk\x1b[0mreplayed` — the early bytes ahead of the snapshot,
  which is the corruption the reset prevents.
- The transport, both ways: the native document installs `message` on `window` and on
  `document` and keeps them, because the WebView never stops its document; the page's
  factory with a no-op transport installs none, so none of the shell's own frames are taken.
  Installing on one target fails the first half, installing a real listener the second.
- What the bundle carries: no input from node_modules, no `__commonJS`, no `__esm(`.
  Pointing the presets back at `storage/preferences` fails it with the six inputs named.

The build options become one object the census and the build share, so what is measured is
what ships.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
2026-09-20 22:17:45 -04:00
..