<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Praveen Singh</title>
    <description>The latest articles on DEV Community by Praveen Singh (@praveensingh).</description>
    <link>https://dev.to/praveensingh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4172772%2F7eb3ceeb-ac00-46c4-9040-5f897425be8d.png</url>
      <title>DEV Community: Praveen Singh</title>
      <link>https://dev.to/praveensingh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/praveensingh"/>
    <language>en</language>
    <item>
      <title>Code review shouldn't catch import rules: a React Native architecture ESLint enforces</title>
      <dc:creator>Praveen Singh</dc:creator>
      <pubDate>Mon, 16 Nov 2026 04:38:53 +0000</pubDate>
      <link>https://dev.to/praveensingh/code-review-shouldnt-catch-import-rules-a-react-native-architecture-eslint-enforces-827</link>
      <guid>https://dev.to/praveensingh/code-review-shouldnt-catch-import-rules-a-react-native-architecture-eslint-enforces-827</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; Bareship writes its architecture down as lint errors instead of a wiki page. ESLint checks that imports go one way through five layers and that features never import each other, and dependency-cruiser checks the whole graph again in CI. Other rules each came from a real bug: hard-coded text, &lt;code&gt;left&lt;/code&gt;/&lt;code&gt;right&lt;/code&gt; styles that don't mirror in right-to-left languages, and calls the React Compiler caches. Every error message says how to fix it and links the decision behind it, so a teammate or an AI agent can fix the code without asking anyone.&lt;/p&gt;

&lt;p&gt;This is Part 3 of Building Bareship. &lt;a href="https://www.praveensingh.co.in/blog/bareship-offline-write-queue" rel="noopener noreferrer"&gt;Part 2&lt;/a&gt; covered the offline queue and&lt;br&gt;
ended with a promise: an architecture the linter enforces.&lt;/p&gt;

&lt;p&gt;Every React Native project starts with folders and good intentions. Someone draws the layers on a whiteboard,&lt;br&gt;
everyone agrees, and it holds for a few weeks. Then a settings screen borrows a hook from the feed because it's&lt;br&gt;
quicker, a string skips translation because it's "temporary", and the person who knew the rules is on leave. Code&lt;br&gt;
review is supposed to catch this, but reviewers are looking at whether the feature works, not at import paths.&lt;/p&gt;

&lt;p&gt;So in Bareship the rules are errors. They show up in the editor while you type, block the commit, and fail CI.&lt;/p&gt;
&lt;h2&gt;
  
  
  One file, three errors
&lt;/h2&gt;

&lt;p&gt;Here's a small screen I wrote to break the rules on purpose. It sits in the settings feature, shows how many&lt;br&gt;
pages of posts the feed has loaded, and adds a little margin:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/features/settings/screens/ProfileCard.tsx&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;View&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-native'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;StyleSheet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-native-unistyles'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;useFeed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/features/feed/api'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/shared/ui/primitives/Text'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;ProfileCard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;feed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useFeed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Your&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;feed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;styles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;marginLeft&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It type-checks and it runs. ESLint says no, three times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/features/settings/screens/ProfileCard.tsx
   4:25  error  Layer rule broken. Imports go app → features → entities → data → shared,
                and features never import each other (docs/decisions/0005)   boundaries/dependencies
  11:13  error  disallow literal string: &amp;lt;Text&amp;gt;Your posts: {feed.data?.pages.length}&amp;lt;/Text&amp;gt;
                                                                              i18next/no-literal-string
  16:44  error  Use start/end (marginStart, paddingEnd, start, borderStartWidth…) so the layout
                mirrors in right-to-left languages (ADR 0017)                  no-restricted-syntax

✖ 3 problems (3 errors, 0 warnings)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And dependency-cruiser, which CI runs over the whole import graph, catches the first one again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  error features-are-isolated: src/features/settings/screens/ProfileCard.tsx → src/features/feed/api.ts

x 1 dependency violations (1 errors, 0 warnings). 226 modules, 722 dependencies cruised.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;None of these would have broken a test. Each one costs real time later: the settings feature now breaks when the&lt;br&gt;
feed changes, the text can't be translated, and the margin is on the wrong side in Arabic or Urdu.&lt;/p&gt;
&lt;h2&gt;
  
  
  Layers, and features that don't know each other
&lt;/h2&gt;

&lt;p&gt;The code in &lt;code&gt;src/&lt;/code&gt; is split into five layers, and imports only go down:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Holds&lt;/th&gt;
&lt;th&gt;May import&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;app&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Navigation, boot, providers&lt;/td&gt;
&lt;td&gt;everything below&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;features&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;One folder per feature: screens, hooks, API calls&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;entities&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt;, &lt;code&gt;shared&lt;/code&gt;, and only itself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;entities&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Domain models more than one feature needs, such as the session and the user&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;data&lt;/code&gt;, &lt;code&gt;shared&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;data&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The query client, the offline queue, storage&lt;/td&gt;
&lt;td&gt;&lt;code&gt;shared&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;shared&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;UI primitives, the HTTP client, i18n, config&lt;/td&gt;
&lt;td&gt;&lt;code&gt;shared&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The rule that matters most is the one in the middle row: &lt;strong&gt;a feature never imports another feature&lt;/strong&gt;. If the&lt;br&gt;
settings screen needs the feed's data, that's a sign the shared part belongs lower down, in &lt;code&gt;entities&lt;/code&gt; or &lt;code&gt;shared&lt;/code&gt;.&lt;br&gt;
Then you can delete or rewrite the feed without touching settings, which is also how &lt;code&gt;pnpm strip-examples&lt;/code&gt; can&lt;br&gt;
remove the whole demo with one command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/javierbrea/eslint-plugin-boundaries" rel="noopener noreferrer"&gt;eslint-plugin-boundaries&lt;/a&gt; enforces this in the editor.&lt;br&gt;
The whole policy is generated from one list, so the order of the layers is written down exactly once:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;eslint.config.mjs&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;LAYERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'features'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'entities'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'data'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'shared'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="s1"&gt;'boundaries/dependencies'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'error'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'disallow'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s1"&gt;'Layer rule broken. Imports go app → features → entities → data → shared, and features never import each other (docs/decisions/0005).'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;policies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;LAYERS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;layer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;layer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;allow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="c1"&gt;// Every layer below this one.&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;LAYERS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="c1"&gt;// Within the same layer: a feature only into itself; other layers freely.&lt;/span&gt;
      &lt;span class="n"&gt;layer&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'features'&lt;/span&gt;
        &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'features'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;captured&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;feature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'{{ from.element.captured.feature }}'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;layer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two more import rules sit on top. &lt;code&gt;app&lt;/code&gt; may use a feature only through its &lt;code&gt;index.ts&lt;/code&gt;, its public API, and never&lt;br&gt;
reach into its files. And nobody imports a folder's &lt;code&gt;index.ts&lt;/code&gt; barrel inside the layers: barrels caused require&lt;br&gt;
cycles and loaded more than a screen needed. Removing them touched 29 files, and the Android release bundle went&lt;br&gt;
from 3,831 to 3,824 KB.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sverweij/dependency-cruiser" rel="noopener noreferrer"&gt;dependency-cruiser&lt;/a&gt; checks the same layer rules a second time, over&lt;br&gt;
the whole graph at once. It also catches what a per-file linter can't see: import cycles across many files, and app&lt;br&gt;
code that imports a dev dependency, such as a test or mock tool that should never ship in the app.&lt;/p&gt;
&lt;h2&gt;
  
  
  Rules that each came from a bug
&lt;/h2&gt;

&lt;p&gt;The layer rules came from a plan. Most of the others came from something that went wrong, and I added the rule so&lt;br&gt;
it couldn't happen twice:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rule&lt;/th&gt;
&lt;th&gt;The bug behind it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No &lt;code&gt;formatRelative(date)&lt;/code&gt; or &lt;code&gt;formatDate(…)&lt;/code&gt; directly in JSX&lt;/td&gt;
&lt;td&gt;After switching to Hindi, "2 days ago" stayed in English. The React Compiler had cached the call, which didn't know the language changed. Components use &lt;code&gt;useFormat()&lt;/code&gt; instead.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No &lt;code&gt;left&lt;/code&gt;/&lt;code&gt;right&lt;/code&gt;, &lt;code&gt;marginLeft&lt;/code&gt;, &lt;code&gt;paddingRight&lt;/code&gt; and friends in styles&lt;/td&gt;
&lt;td&gt;Physical sides don't flip in right-to-left languages; &lt;code&gt;start&lt;/code&gt;/&lt;code&gt;end&lt;/code&gt; do.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No &lt;code&gt;textAlign: 'left'&lt;/code&gt; or &lt;code&gt;'right'&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;On iOS, text in a mirrored row stayed on the left (&lt;a href="https://github.com/psingh2907/bareship/pull/21" rel="noopener noreferrer"&gt;#21&lt;/a&gt;).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No &lt;code&gt;useVariants&lt;/code&gt; from Unistyles&lt;/td&gt;
&lt;td&gt;The React Compiler memoized the style array without knowing the variant changed, so the old one stayed on screen: a focus border that never cleared. A style function, &lt;code&gt;styles.field(state)&lt;/code&gt;, stays correct.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No icons from the &lt;code&gt;lucide-react-native&lt;/code&gt; root&lt;/td&gt;
&lt;td&gt;Metro can't tree-shake, so a root import bundles every icon. Icons come from one module each.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ARIA props only (&lt;code&gt;role&lt;/code&gt;, &lt;code&gt;aria-label&lt;/code&gt;…), not &lt;code&gt;accessibilityRole&lt;/code&gt; and friends&lt;/td&gt;
&lt;td&gt;One way to write it, which is also what agents that read the screen as text understand.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No hard-coded text in JSX&lt;/td&gt;
&lt;td&gt;Every word goes through &lt;code&gt;t('…')&lt;/code&gt;, so a new language is a new file, not a hunt through screens.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On top of these, the 15 React Compiler rules from &lt;code&gt;eslint-plugin-react-hooks&lt;/code&gt; are all errors, not warnings.&lt;/p&gt;

&lt;p&gt;Most of the table needs no plugin. ESLint's built-in &lt;code&gt;no-restricted-syntax&lt;/code&gt; takes an AST selector and a message,&lt;br&gt;
which is enough for a lot of house rules:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;eslint.config.mjs&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Physical sides don't flip in right-to-left languages; start/end do (ADR 0017).&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s1"&gt;'Property[key.name=/^(left|right|(margin|padding)(Left|Right)|border(Top|Bottom)?(Left|Right)(Width|Color|Radius)?)$/]'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s1"&gt;'Use start/end (marginStart, paddingEnd, start, borderStartWidth…) so the layout mirrors in right-to-left languages (ADR 0017).'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you only take one idea from this post, take this one: when a bug comes from a pattern, a ten-line lint rule&lt;br&gt;
stops the whole class of bug, in every file, for every future developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error messages that teach
&lt;/h2&gt;

&lt;p&gt;Look at the messages again. None of them just says "not allowed". Each one says what to do instead, and most&lt;br&gt;
name the decision record that explains why: &lt;code&gt;docs/decisions/0005&lt;/code&gt;, &lt;code&gt;ADR 0017&lt;/code&gt;, &lt;code&gt;AGENTS.md › Styling&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That matters for people: a new teammate fixes the code from the message, without asking anyone or opening a wiki.&lt;br&gt;
It matters even more for AI coding agents. I built much of Bareship with Claude Code, and an agent reads a lint&lt;br&gt;
error far more reliably than it remembers a paragraph of guidelines. &lt;code&gt;AGENTS.md&lt;/code&gt; has one line about these rules:&lt;br&gt;
"Fix the import, never disable the rule." When the agent broke a rule, the fix went into the linter or its&lt;br&gt;
message, not into a comment on a pull request. The next agent, or the next person, then gets the right answer from&lt;br&gt;
the tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the rules run
&lt;/h2&gt;

&lt;p&gt;The same rules run in four places, from fastest to last line of defence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;In the editor&lt;/strong&gt;, as you type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On every commit&lt;/strong&gt;: a pre-commit hook runs &lt;code&gt;eslint --fix --max-warnings=0&lt;/code&gt; on the staged files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pnpm check&lt;/code&gt;&lt;/strong&gt;: types, lint, formatting, dependency-cruiser and tests in one command.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI on every pull request&lt;/strong&gt;, where the lint and dependency checks are required before anything reaches &lt;code&gt;main&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What it costs
&lt;/h2&gt;

&lt;p&gt;The first week with rules like these feels strict. A quick fix you'd normally push needs a moment's thought about&lt;br&gt;
where the code belongs. After that, nobody has to remember the rules, and review is about the feature again.&lt;/p&gt;

&lt;p&gt;The rules also have to cover your own tools. The &lt;code&gt;formatRelative&lt;/code&gt; rule arrived in 0.2, but the feature generator&lt;br&gt;
kept writing a list screen that called it. So in 0.4.0, &lt;code&gt;pnpm gen feature&lt;/code&gt; produced code its own linter rejected.&lt;br&gt;
Nothing ran the generators end to end, so nobody noticed until I tried one while writing a post. 0.4.1 fixed the&lt;br&gt;
template and added &lt;code&gt;scripts/ci/check-generators.sh&lt;/code&gt;, which runs every generator on a scratch copy and checks the&lt;br&gt;
result for types, lint, formatting, boundaries and tests.&lt;/p&gt;

&lt;p&gt;And sometimes a rule is wrong for your app. Then you change it in one place, in &lt;code&gt;eslint.config.mjs&lt;/code&gt;, and write&lt;br&gt;
down why in a decision record next to the others. That's the point: a rule you disagree with is a conversation&lt;br&gt;
about one line of config, not about whose turn it is to be strict in review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-bareship Acme
&lt;span class="nb"&gt;cd&lt;/span&gt; Acme
pnpm lint
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste the &lt;code&gt;ProfileCard&lt;/code&gt; above into &lt;code&gt;src/features/settings/screens/&lt;/code&gt; and run &lt;code&gt;pnpm lint&lt;/code&gt; again to see the three&lt;br&gt;
errors. &lt;code&gt;pnpm depcruise&lt;/code&gt; shows the graph check.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Config: &lt;a href="https://github.com/psingh2907/bareship/blob/main/eslint.config.mjs" rel="noopener noreferrer"&gt;&lt;code&gt;eslint.config.mjs&lt;/code&gt;&lt;/a&gt; and
&lt;a href="https://github.com/psingh2907/bareship/blob/main/.dependency-cruiser.cjs" rel="noopener noreferrer"&gt;&lt;code&gt;.dependency-cruiser.cjs&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The rules in plain words: &lt;a href="https://bareship.praveensingh.co.in/build/project-rules/" rel="noopener noreferrer"&gt;Project rules&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The decision: &lt;a href="https://bareship.praveensingh.co.in/reference/decisions/0005-architecture-and-boundaries/" rel="noopener noreferrer"&gt;ADR 0005, architecture and boundaries&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Next in the series:&lt;/strong&gt; a package manager that refuses packages younger than three days, and the rest of&lt;br&gt;
Bareship's supply-chain rules.&lt;/p&gt;

&lt;p&gt;If one of these rules would get in your way, or you have one I should add, leave a comment on dev.to or open an&lt;br&gt;
issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How do you enforce architecture layers in a React Native app?
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;eslint-plugin-boundaries&lt;/code&gt; to define each folder as a layer and allow imports only to the layers below it,&lt;br&gt;
and run &lt;code&gt;dependency-cruiser&lt;/code&gt; in CI to check the whole import graph, including cycles.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do you stop one feature folder importing another?
&lt;/h3&gt;

&lt;p&gt;Give each feature its own element in &lt;code&gt;eslint-plugin-boundaries&lt;/code&gt;, captured by folder name, and allow imports within&lt;br&gt;
the same feature only. Code two features need moves down to a shared layer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can ESLint catch React Native right-to-left layout bugs?
&lt;/h3&gt;

&lt;p&gt;Yes. &lt;code&gt;no-restricted-syntax&lt;/code&gt; with a selector on style keys can reject &lt;code&gt;left&lt;/code&gt;, &lt;code&gt;right&lt;/code&gt;, &lt;code&gt;marginLeft&lt;/code&gt; and similar,&lt;br&gt;
and suggest &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt;, which mirror in right-to-left languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Bareship's five layers import downward only, and features never import each other; ESLint and dependency-cruiser both check it.&lt;/li&gt;
&lt;li&gt;Generate the boundaries policy from one ordered list, so the layer order is written down once.&lt;/li&gt;
&lt;li&gt;Most house rules need no plugin: no-restricted-syntax with an AST selector and a clear message is enough.&lt;/li&gt;
&lt;li&gt;Every error message names the fix and the decision behind it, which is what lets an AI agent fix its own code.&lt;/li&gt;
&lt;li&gt;Rules must cover your own generators too: Bareship 0.4.1 added a check that runs every generator and checks its output.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about React Native in practice, measured and with public code, at &lt;a href="https://www.praveensingh.co.in/blog" rel="noopener noreferrer"&gt;praveensingh.co.in/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>architecture</category>
      <category>eslint</category>
      <category>javascript</category>
    </item>
    <item>
      <title>An offline write queue for React Native, and the two reader questions that changed it</title>
      <dc:creator>Praveen Singh</dc:creator>
      <pubDate>Sun, 15 Nov 2026 04:04:43 +0000</pubDate>
      <link>https://dev.to/praveensingh/an-offline-write-queue-for-react-native-and-the-two-reader-questions-that-changed-it-5gfh</link>
      <guid>https://dev.to/praveensingh/an-offline-write-queue-for-react-native-and-the-two-reader-questions-that-changed-it-5gfh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; Bareship queues offline writes with TanStack Query: a paused mutation is saved to MMKV, so it survives the app being killed, and replays in order when the phone reconnects. Every write gets an &lt;code&gt;Idempotency-Key&lt;/code&gt; when the user taps, reused for every attempt, so the server applies it once. Since 0.4.0, each write also records the account that made it and is never sent for anyone else, and a write can cancel the dependent writes queued behind it if the server rejects it.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://www.praveensingh.co.in/blog/introducing-bareship" rel="noopener noreferrer"&gt;launch post&lt;/a&gt; I said Bareship saves a like made offline, keeps it through a&lt;br&gt;
restart and sends it once when the phone reconnects, and promised the next post would show how.&lt;/p&gt;

&lt;p&gt;Two readers on dev.to then asked questions I hadn't fully answered. &lt;a href="https://dev.to/davekurian"&gt;Dave Kurian&lt;/a&gt;&lt;br&gt;
asked whose write it is when someone else signs in before it's sent. &lt;a href="https://dev.to/oddeggs"&gt;Odd Eggs Studio&lt;/a&gt;&lt;br&gt;
asked what happens to the writes behind one the server rejects. Both answers are now code, released in&lt;br&gt;
&lt;a href="https://github.com/psingh2907/bareship/releases/tag/v0.4.0" rel="noopener noreferrer"&gt;0.4.0&lt;/a&gt;. This post walks through the queue from the tap&lt;br&gt;
to the server, with those two changes in the places they belong.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffacw6kx1u4yvzddg3crq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffacw6kx1u4yvzddg3crq.gif" alt="On Android: airplane mode on, a like is saved and marked &amp;quot;Waiting to sync&amp;quot;, then sent when the phone is back online" width="480" height="853"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What can go wrong with one like
&lt;/h2&gt;

&lt;p&gt;Someone likes a post on a train with no signal. Before that like reaches your server, any of these can happen:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user swipes the app away, or the OS kills it.&lt;/li&gt;
&lt;li&gt;The request goes out, the connection drops before the answer comes back, and the app tries again. Now the
server has seen it twice.&lt;/li&gt;
&lt;li&gt;They like, then unlike. The two requests arrive in the wrong order.&lt;/li&gt;
&lt;li&gt;They sign out and someone else signs in on the same phone. The like is still waiting.&lt;/li&gt;
&lt;li&gt;The server refuses the like for good, and three edits that depend on it are queued behind it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A queue that only handles the first one still looks fine in a demo. The other four show up later, in bug reports&lt;br&gt;
you can't reproduce. (For the wider design questions, such as a local database, conflicts and photo uploads, see my&lt;br&gt;
&lt;a href="https://www.praveensingh.co.in/blog/offline-first-react-native-data-layer" rel="noopener noreferrer"&gt;offline-first data layer post&lt;/a&gt;. This one is about the write queue&lt;br&gt;
only.)&lt;/p&gt;
&lt;h2&gt;
  
  
  The base: TanStack Query, with the gaps filled
&lt;/h2&gt;

&lt;p&gt;Bareship doesn't have its own queue engine. TanStack Query already does most of the work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A mutation with &lt;code&gt;networkMode: 'online'&lt;/code&gt; &lt;strong&gt;pauses&lt;/strong&gt; while the phone is offline instead of failing, and resumes
when the connection returns.&lt;/li&gt;
&lt;li&gt;Paused mutations can be &lt;strong&gt;saved&lt;/strong&gt; with the query cache. Bareship stores that cache in MMKV, so a waiting write
survives the app being killed.&lt;/li&gt;
&lt;li&gt;Mutations that share a &lt;strong&gt;scope&lt;/strong&gt; run one at a time, in the order they were made. That handles problem 3.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The gap is in what gets saved. A restored mutation is only data: its key and its variables. The functions that&lt;br&gt;
send it and update the screen aren't saved, because you can't save a function. TanStack Query looks them up by&lt;br&gt;
the mutation's key in the defaults registered on the client. If nothing is registered yet when the saved cache&lt;br&gt;
comes back, the write fails with "No mutationFn found".&lt;/p&gt;

&lt;p&gt;In React Native that's easy to get wrong. Metro loads modules lazily, so the feature that defines the like may not&lt;br&gt;
have run yet when the cache is restored at startup. Bareship fixes this with one file, &lt;code&gt;src/app/queued-writes.ts&lt;/code&gt;,&lt;br&gt;
which imports every module that defines a queued write and is imported before the cache is restored. A test fails&lt;br&gt;
if a definition is missing from it. A write whose definition really is gone, say removed in an app update, is&lt;br&gt;
dropped and logged at startup instead of crashing.&lt;/p&gt;

&lt;p&gt;From the feature's side, a queued write is one definition at module level:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/features/feed/api.ts&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;likeKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'like'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;useToggleLike&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;defineQueuedMutation&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;mutationKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;likeKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;mutationFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idempotencyKey&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`/posts/${encodeURIComponent(postId)}/like`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt;
      &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PostSchema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;idempotencyKey&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PostSchema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;idempotencyKey&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;onMutate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;queryClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancelQueries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;queryKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;postKeys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;updatePost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queryClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;applyLike&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;like&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// show it at once&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;onError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;updatePost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queryClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;applyLike&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;like&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// undo it&lt;/span&gt;
    &lt;span class="n"&gt;toast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i18n&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'feed.likeFailed'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;onSuccess&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;updated&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;postId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// A like then an unlike queued offline: keep the optimistic state until the last one lands.&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;hasLaterWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;likeKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variables&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;postId&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;updatePost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queryClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;updated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;updated&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cache work lives in these callbacks, not in the screen, because after a restart the screen that started the&lt;br&gt;
write is gone. The variables are saved as JSON, so they stay small: ids and flags, not whole objects.&lt;/p&gt;

&lt;p&gt;The "Waiting to sync" label comes from the paused writes themselves. &lt;code&gt;useWaitingWrites(likeKey)&lt;/code&gt; returns the&lt;br&gt;
variables of every like still waiting, and the banner under the header counts them. Nothing is tracked twice.&lt;/p&gt;
&lt;h2&gt;
  
  
  Sent twice, applied once: idempotency keys
&lt;/h2&gt;

&lt;p&gt;Problem 2 can't be solved on the phone alone. If the connection drops after the server got the request, the app&lt;br&gt;
can't know whether the like landed. It has to try again, so the server has to recognise a repeat.&lt;/p&gt;

&lt;p&gt;Every queued write gets an &lt;code&gt;Idempotency-Key&lt;/code&gt; (a random UUID) &lt;strong&gt;when the user taps&lt;/strong&gt;, not when the request is sent.&lt;br&gt;
That one key goes with every attempt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The HTTP client retries network errors, timeouts, 408, 429 and 5xx with backoff, up to 3 attempts in all. It
reuses the key each time.&lt;/li&gt;
&lt;li&gt;A write replayed after a restart reuses the key.&lt;/li&gt;
&lt;li&gt;A write the server already answered is never sent again.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the server, the rule is to store the first response for each key and return it for repeats. Here's the mock&lt;br&gt;
backend that ships with the template, which does exactly that for likes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/mocks/handlers.ts&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Idempotency-Key'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;replay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;idempotency&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;replay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;HttpResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;replay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// seen it: same answer, applied once&lt;/span&gt;

&lt;span class="c1"&gt;// ...apply the like...&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;postDto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;idempotency&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;HttpResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One limit, written down in the code: a write that's already on the wire when the app dies isn't saved, because&lt;br&gt;
it's no longer paused. Its key still makes a manual retry safe.&lt;/p&gt;
&lt;h2&gt;
  
  
  Question 1: whose write is it?
&lt;/h2&gt;

&lt;p&gt;Dave's question was about problem 4. A like is queued, the user signs out, someone else signs in, the phone&lt;br&gt;
reconnects. Does the first user's like go out with the second user's token?&lt;/p&gt;

&lt;p&gt;My answer at the time was "no, because sign-out clears the queue". That was true, but the guarantee lived in the&lt;br&gt;
sign-out flow. Any future change there, like account switching or a sign-out that fails halfway, could break it&lt;br&gt;
without anyone noticing. Dave suggested storing the account next to the key, and he was right.&lt;/p&gt;

&lt;p&gt;Now each write records who made it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/data/offline.ts&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="n"&gt;mutate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;variables&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="n"&gt;mutation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mutate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idempotencyKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;createId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;currentAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's checked twice. The first check is when the saved queue comes back after a restart. The second is just before&lt;br&gt;
each write is sent, because the account can change while a write waits offline:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/data/offline.ts&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="n"&gt;mutationFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;variables&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;belongsToCurrentAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OtherAccountWriteError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;mutationFn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A write from another account is dropped and logged. It never reaches the server, and it doesn't call the&lt;br&gt;
feature's &lt;code&gt;onError&lt;/code&gt;, so the new user doesn't see someone else's rollback or error message. Writes saved by older&lt;br&gt;
versions have no account id and replay as before.&lt;/p&gt;

&lt;p&gt;The server side matters too: keep idempotency keys per user, so a replayed key can never match another account's&lt;br&gt;
record. That's now in the docs.&lt;/p&gt;
&lt;h2&gt;
  
  
  Question 2: what if the server says no?
&lt;/h2&gt;

&lt;p&gt;Odd Eggs Studio asked about problem 5. If a queued write is rejected, does the queue stop or carry on?&lt;/p&gt;

&lt;p&gt;It carries on, and for likes that's right: each like stands alone, so one refused like shouldn't block the next.&lt;br&gt;
But some writes depend on each other. "Create a draft, then edit it" is the usual example. If the create fails,&lt;br&gt;
sending the edit only produces a second error, and the screen is left showing a draft that doesn't exist.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;defineQueuedMutation&lt;/code&gt; now takes &lt;code&gt;onRejected&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/features/drafts/api.ts&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;useCreateDraft&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;defineQueuedMutation&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Draft&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;draftId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;mutationKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'drafts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'create'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'drafts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;onRejected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'cancel-scope'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// if this fails for good, drop the drafts writes queued behind it&lt;/span&gt;
  &lt;span class="n"&gt;mutationFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; …&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;useEditDraft&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;defineQueuedMutation&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Draft&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;draftId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;mutationKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'drafts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'edit'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'drafts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;mutationFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; …&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;onError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;draftId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Runs for a cancelled edit too (error.kind === 'cancelled'): undo its optimistic update.&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The details that took the most thought:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;"Fails for good"&lt;/strong&gt; means the server refused the write, or it still failed after the HTTP client's retries.
Going offline isn't a failure: the queue just pauses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Each cancelled write gets its own &lt;code&gt;onError&lt;/code&gt;&lt;/strong&gt;, with an error of kind &lt;code&gt;'cancelled'&lt;/code&gt;. Every write rolls back its
own optimistic update, so the screen ends up correct without the failed write having to know what came after it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only writes already queued are cancelled.&lt;/strong&gt; Something the user does after the failure runs normally.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The limit:&lt;/strong&gt; if the app is killed between the failure and the next launch, the cancellation isn't remembered.
The writes behind it go out and fail on their own, as they did before. I wrote this down in the docs instead of
adding more machinery for a rare case.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I took from this
&lt;/h2&gt;

&lt;p&gt;Both changes came from comments on a launch post. Each one turned into an issue, a change with tests, a docs&lt;br&gt;
section and a release. Two things stood out to me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Put a guarantee in the data, not in a flow.&lt;/strong&gt; "Sign-out clears the queue" was true, but it depended on code far
from the queue. "Every write knows its account" stays true whatever happens elsewhere.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Default to the simple behaviour, and make the strict one a single line.&lt;/strong&gt; Most writes are independent, so
&lt;code&gt;'continue'&lt;/code&gt; stays the default. The chains that need more get &lt;code&gt;'cancel-scope'&lt;/code&gt;, and the limit is written next to
it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-bareship Acme
&lt;span class="nb"&gt;cd&lt;/span&gt; Acme
pnpm android   &lt;span class="c"&gt;# or: pnpm ios&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sign in with &lt;code&gt;demo@example.com&lt;/code&gt; / &lt;code&gt;password123&lt;/code&gt;, turn on airplane mode, like a post, close the app, open it again,&lt;br&gt;
then turn airplane mode off. The like is sent once. The mock backend runs inside the app, so you don't need a&lt;br&gt;
server for any of this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Queue code: &lt;a href="https://github.com/psingh2907/bareship/blob/main/src/data/offline.ts" rel="noopener noreferrer"&gt;&lt;code&gt;src/data/offline.ts&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Guide: &lt;a href="https://bareship.praveensingh.co.in/build/offline/" rel="noopener noreferrer"&gt;Offline&lt;/a&gt; and
&lt;a href="https://bareship.praveensingh.co.in/build/architecture/#writes-that-depend-on-each-other" rel="noopener noreferrer"&gt;writes that depend on each other&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The two changes: &lt;a href="https://github.com/psingh2907/bareship/pull/28" rel="noopener noreferrer"&gt;#28&lt;/a&gt; (account) and
&lt;a href="https://github.com/psingh2907/bareship/pull/29" rel="noopener noreferrer"&gt;#29&lt;/a&gt; (&lt;code&gt;onRejected&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Next in the series:&lt;/strong&gt; an architecture the linter enforces. Layers and feature boundaries that ESLint checks, so&lt;br&gt;
code review doesn't have to.&lt;/p&gt;

&lt;p&gt;If you have a question like Dave's or Odd Eggs Studio's, leave it in the comments on dev.to or open an issue. Two of&lt;br&gt;
them have already made the template better.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How does Bareship keep offline writes after the app is killed?
&lt;/h3&gt;

&lt;p&gt;Queued writes are TanStack Query mutations that pause while offline. Paused mutations are saved with the query&lt;br&gt;
cache in MMKV and replayed in order on the next launch, once every write's definition is registered.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does Bareship stop a write from being applied twice?
&lt;/h3&gt;

&lt;p&gt;Each write gets an &lt;code&gt;Idempotency-Key&lt;/code&gt; when the user taps, and every retry or replay sends the same key. The server&lt;br&gt;
stores the first response for each key and returns it for repeats.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can a queued write be sent under another user's account?
&lt;/h3&gt;

&lt;p&gt;No. Since 0.4.0 each write records the account that made it, and it's checked on restore and before every send.&lt;br&gt;
A write from another account is dropped and logged, without calling the feature's error handler.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Bareship's offline queue is TanStack Query paused mutations, saved to MMKV and replayed in order after a restart.&lt;/li&gt;
&lt;li&gt;Register every queued write's definition before the saved cache is restored: Metro loads modules lazily.&lt;/li&gt;
&lt;li&gt;One Idempotency-Key per write, made when the user taps and reused for every attempt, so the server applies it once.&lt;/li&gt;
&lt;li&gt;Each queued write records its account and is checked on restore and before every send (0.4.0).&lt;/li&gt;
&lt;li&gt;onRejected: 'cancel-scope' drops the dependent writes behind a rejected one, and each rolls back its own update.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about React Native in practice, measured and with public code, at &lt;a href="https://www.praveensingh.co.in/blog" rel="noopener noreferrer"&gt;praveensingh.co.in/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>mobile</category>
      <category>javascript</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Making a React Native app agent-ready: what happens when Siri calls and your JavaScript isn't running</title>
      <dc:creator>Praveen Singh</dc:creator>
      <pubDate>Thu, 12 Nov 2026 12:26:55 +0000</pubDate>
      <link>https://dev.to/praveensingh/making-a-react-native-app-agent-ready-what-happens-when-siri-calls-and-your-javascript-isnt-4d00</link>
      <guid>https://dev.to/praveensingh/making-a-react-native-app-agent-ready-what-happens-when-siri-calls-and-your-javascript-isnt-4d00</guid>
      <description>&lt;p&gt;&lt;strong&gt;At a glance&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Problem: Siri or Gemini calls your React Native app while its JavaScript isn't running&lt;/li&gt;
&lt;li&gt;Fix: Do the work natively, against the same database and the same SQLite copy as your JavaScript&lt;/li&gt;
&lt;li&gt;Result: 5 ms vs next launch (time to save a task with the app closed: done in Swift vs queued for JavaScript)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; With &lt;code&gt;expo-app-intents&lt;/code&gt;, Siri can call a React Native app, but &lt;code&gt;perform()&lt;/code&gt; runs in Swift and the library only queues the call for JavaScript. With the app closed, a queued task wasn't saved until the app was next opened. Opening the app works but takes about 2 seconds of cold JavaScript start. Doing the work in Swift saved the task in 5–23 ms, but only after one fix: Swift has to use expo-sqlite's own copy of SQLite. With the system copy, the app silently lost a task JavaScript had just saved. Android's AppFunctions have the same shape and, from the expo-sqlite source, the same SQLite risk; I haven't run the Android half yet.&lt;/p&gt;

&lt;p&gt;Assistants are learning to use apps without opening them. On iOS, the way in is App Intents: at WWDC26 Apple&lt;br&gt;
called it &lt;a href="https://developer.apple.com/videos/play/wwdc2026/345/" rel="noopener noreferrer"&gt;"a key pillar of Apple Intelligence"&lt;/a&gt;, and it's&lt;br&gt;
what Siri, Shortcuts and Spotlight call. On Android, Gemini calls apps through&lt;br&gt;
&lt;a href="https://developer.android.com/ai/appfunctions" rel="noopener noreferrer"&gt;AppFunctions&lt;/a&gt;, an Android 16 API whose Gemini integration Google's docs&lt;br&gt;
describe as a private preview (as of May 2026).&lt;/p&gt;

&lt;p&gt;React Native got its way in in September. Expo SDK 58 beta (September 15, React Native 0.88 RC) ships&lt;br&gt;
&lt;a href="https://docs.expo.dev/versions/v58.0.0/sdk/app-intents/" rel="noopener noreferrer"&gt;&lt;code&gt;expo-app-intents&lt;/code&gt;&lt;/a&gt;, an alpha library that exposes App&lt;br&gt;
Intents, Siri, Shortcuts, Spotlight and Apple Intelligence from an Expo app.&lt;/p&gt;

&lt;p&gt;My &lt;a href="https://www.praveensingh.co.in/blog/on-device-ai-react-native-2026" rel="noopener noreferrer"&gt;on-device AI post&lt;/a&gt; put a model inside the app, and the&lt;br&gt;
&lt;a href="https://www.praveensingh.co.in/blog/coding-agents-drive-the-simulator" rel="noopener noreferrer"&gt;coding agents post&lt;/a&gt; let an agent drive the app during development. This&lt;br&gt;
one is the third angle: an assistant calling your app in production, with no UI. I built a small task app, exposed&lt;br&gt;
it to Siri, and measured the one thing the docs don't spell out: what happens when the call arrives and your&lt;br&gt;
JavaScript isn't running.&lt;/p&gt;

&lt;p&gt;Everything is in &lt;a href="https://github.com/psingh2907/rn-agent-ready-lab" rel="noopener noreferrer"&gt;a public repo&lt;/a&gt;: code, raw results and the bug.&lt;/p&gt;
&lt;h2&gt;
  
  
  Your app is now a tool
&lt;/h2&gt;

&lt;p&gt;If you've written an MCP tool, you already know the shape. An App Intent and an AppFunction are tools that live on&lt;br&gt;
the phone:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;MCP tool&lt;/th&gt;
&lt;th&gt;App Intent (iOS)&lt;/th&gt;
&lt;th&gt;AppFunction (Android)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Declared in&lt;/td&gt;
&lt;td&gt;Server code&lt;/td&gt;
&lt;td&gt;Swift, compiled into the app&lt;/td&gt;
&lt;td&gt;Kotlin, annotated, compiled into the app&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The model reads&lt;/td&gt;
&lt;td&gt;Tool description&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;title&lt;/code&gt;, &lt;code&gt;description&lt;/code&gt;, parameter titles, phrases&lt;/td&gt;
&lt;td&gt;KDoc on the function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Typed inputs&lt;/td&gt;
&lt;td&gt;JSON Schema&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;@Parameter&lt;/code&gt;, &lt;code&gt;AppEntity&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;@AppFunctionSerializable&lt;/code&gt; classes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Who can call it&lt;/td&gt;
&lt;td&gt;Any MCP client&lt;/td&gt;
&lt;td&gt;Siri, Shortcuts, Spotlight, Apple Intelligence&lt;/td&gt;
&lt;td&gt;Callers holding &lt;code&gt;EXECUTE_APP_FUNCTIONS&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The difference that matters for React Native is in the first row. Both platforms read these declarations &lt;strong&gt;at&lt;br&gt;
build time&lt;/strong&gt;, from native code in the app. You can't register an action from JavaScript at runtime. That's why&lt;br&gt;
&lt;code&gt;expo-app-intents&lt;/code&gt; has you write intents in Swift, in an &lt;code&gt;app-intents/&lt;/code&gt; folder that Expo compiles into the app&lt;br&gt;
target as an inline module.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up expo-app-intents
&lt;/h2&gt;

&lt;p&gt;The setup is short. Install the library in an Expo SDK 58 project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx expo install expo-app-intents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add its config plugin, and tell Expo to compile the &lt;code&gt;app-intents/&lt;/code&gt; folder into the app target as an inline&lt;br&gt;
module:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;app.json (excerpt)&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"expo"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"plugins"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"expo-app-intents"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"experiments"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"inlineModules"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"watchedDirectories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"app-intents"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each intent is a Swift &lt;code&gt;AppIntent&lt;/code&gt; in that folder. The smallest useful one hands the call to JavaScript:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;app-intents/TaskIntents.swift (excerpt)&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;AppIntents&lt;/span&gt;
&lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ExpoAppIntents&lt;/span&gt;

&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;AddTaskQueuedIntent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AppIntent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;LocalizedStringResource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Add Task (Queued)"&lt;/span&gt;
  &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;IntentDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Adds a task to today's list the next time the app runs."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="nd"&gt;@Parameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Title"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;taskTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

  &lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;perform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;some&lt;/span&gt; &lt;span class="nc"&gt;IntentResult&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nc"&gt;ProvidesDialog&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;AppIntentDispatcher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"addTask"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dialog&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"\(taskTitle) will be added the next time you open the app."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the JavaScript side, &lt;code&gt;useAppIntents&lt;/code&gt; from &lt;code&gt;expo-app-intents&lt;/code&gt; receives the queued calls (the handler is shown&lt;br&gt;
below), and &lt;code&gt;refreshShortcutsAsync()&lt;/code&gt; updates parameterized shortcuts when your data changes. Rebuild the native app&lt;br&gt;
after adding or changing an intent: they're compiled in, so Metro's fast refresh won't pick them up. The whole lab&lt;br&gt;
setup, including App Shortcuts and an entity, is in the&lt;br&gt;
&lt;a href="https://github.com/psingh2907/rn-agent-ready-lab/tree/main/app-intents" rel="noopener noreferrer"&gt;repo's &lt;code&gt;app-intents/&lt;/code&gt; folder&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That gets a call into your app. What it can do once it's there depends on whether your JavaScript is running.&lt;/p&gt;
&lt;h2&gt;
  
  
  The lab app
&lt;/h2&gt;

&lt;p&gt;A task list with three actions: add a task, complete a task, and list today's tasks. Expo SDK 58 beta, React&lt;br&gt;
Native 0.88.0-rc.3, &lt;code&gt;expo-app-intents&lt;/code&gt; 0.5.3, tasks stored with &lt;code&gt;expo-sqlite&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The three actions cover the three kinds of work an assistant asks for. Adding creates something. Completing&lt;br&gt;
changes something the assistant has to find first ("complete &lt;em&gt;buy milk&lt;/em&gt;"), so the task is an &lt;code&gt;AppEntity&lt;/code&gt;. Listing&lt;br&gt;
returns data for the assistant to read out.&lt;/p&gt;

&lt;p&gt;The measured runs used an iPhone 18 Pro simulator on iOS 27.0 and a Release build. (The SQLite bug below showed up&lt;br&gt;
earlier, in a Debug build.) I had no physical iPhone, so there is no "Hey Siri" in this post: every intent was run&lt;br&gt;
from its App Shortcut tile in the Shortcuts app, which calls the same &lt;code&gt;perform()&lt;/code&gt; that Siri does.&lt;/p&gt;
&lt;h2&gt;
  
  
  The call arrives while your JavaScript isn't running
&lt;/h2&gt;

&lt;p&gt;This is the part that decides your design. When an intent runs (from Siri, Shortcuts or Spotlight), iOS starts your&lt;br&gt;
app's process if it isn't running and calls the intent's &lt;code&gt;perform()&lt;/code&gt;, in Swift. Unless the intent opens the app, this&lt;br&gt;
happens in the background: in my runs, &lt;code&gt;perform()&lt;/code&gt; saw the app as &lt;code&gt;background&lt;/code&gt; every time, and &lt;code&gt;active&lt;/code&gt; or&lt;br&gt;
&lt;code&gt;inactive&lt;/code&gt; only for the design that opens the app. &lt;code&gt;expo-app-intents&lt;/code&gt; gives you one way to reach JavaScript from&lt;br&gt;
there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;AppIntentDispatcher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"addTask"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;dispatch&lt;/code&gt; writes the call to a queue and, if JavaScript is listening, sends it an event. It doesn't start&lt;br&gt;
JavaScript and doesn't wait for it, so there's no way to get an answer back into &lt;code&gt;perform()&lt;/code&gt;. The library's own&lt;br&gt;
agent skill says it plainly: don't tell the user it worked just because a call was queued.&lt;/p&gt;

&lt;p&gt;That leaves three designs. I built all three as separate intents, with the same "add a task" job:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Design&lt;/th&gt;
&lt;th&gt;What &lt;code&gt;perform()&lt;/code&gt; does&lt;/th&gt;
&lt;th&gt;The dialog it returns&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Swift&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Writes the task into the same SQLite file JavaScript uses&lt;/td&gt;
&lt;td&gt;"Added &lt;em&gt;buy milk&lt;/em&gt;."&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Queued&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;dispatch&lt;/code&gt;, and nothing else&lt;/td&gt;
&lt;td&gt;"&lt;em&gt;Buy milk&lt;/em&gt; will be added the next time you open the app."&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Open App&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;dispatch&lt;/code&gt; with &lt;code&gt;openAppWhenRun = true&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;"Opening the app to add &lt;em&gt;buy milk&lt;/em&gt;."&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Delivery from the queue is at least once, so the JavaScript handler has to be safe to run twice. I used the&lt;br&gt;
invocation ID as the task ID, so a replay inserts nothing. It's the same rule as the outbox in my&lt;br&gt;
&lt;a href="https://www.praveensingh.co.in/blog/offline-first-react-native-data-layer#rule-3-make-every-write-safe-to-send-twice" rel="noopener noreferrer"&gt;offline-first post&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="nc"&gt;AppIntents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useAppIntents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pendingIntents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;invocation&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;pendingIntents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invocation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'addTask'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// unknown actions stay queued&lt;/span&gt;
    &lt;span class="c1"&gt;// INSERT OR IGNORE, keyed by invocation.id, in one transaction with the run's metrics&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;addTaskFromIntent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;invocationId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;invocation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invocation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// Remove only after the work succeeded, so a failure stays queued for the next launch.&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;AppIntents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removePendingInvocationAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invocation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Results: what happened with the app closed
&lt;/h2&gt;

&lt;p&gt;I closed the app before each run, then tapped the shortcut. Three runs per design. "Saved" is when the task row&lt;br&gt;
was committed; both clocks are the Mac's, which the simulator shares.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Design&lt;/th&gt;
&lt;th&gt;Tap → &lt;code&gt;perform()&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;perform()&lt;/code&gt; → task saved&lt;/th&gt;
&lt;th&gt;Saved by&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Swift&lt;/td&gt;
&lt;td&gt;5.9–15.3 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;5–23 ms&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Swift&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Queued&lt;/td&gt;
&lt;td&gt;4.8–6.8 s&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;not until I opened the app&lt;/strong&gt; (33–94 s in my runs)&lt;/td&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Open App&lt;/td&gt;
&lt;td&gt;6.0–7.0 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.6–2.3 s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;JavaScript, cold start&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three things stand out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The queue doesn't run your JavaScript.&lt;/strong&gt; iOS woke the app's process to call &lt;code&gt;perform()&lt;/code&gt;, but JavaScript never&lt;br&gt;
handled the queued call. The three queued tasks sat there until I opened the app, and then all three landed within&lt;br&gt;
7 ms of each other. The 33–94 seconds in the table only measure how long I waited; on a real phone it could be hours.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Opening the app costs about 2 seconds, and it isn't "without opening the app".&lt;/strong&gt; The app comes to the front, React&lt;br&gt;
Native starts, and the handler drains the queue. It worked in all three runs, but the user is pulled out of whatever&lt;br&gt;
they were doing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The slow part is launching the app, not the work.&lt;/strong&gt; Tap → &lt;code&gt;perform()&lt;/code&gt; took 5–15 seconds whatever the design. With&lt;br&gt;
the app already running it was 2.3–2.6 seconds, so most of that is iOS starting a closed app. That's simulator time&lt;br&gt;
on a laptop, so don't read it as phone latency. The work itself took 5–23 ms in Swift.&lt;/p&gt;

&lt;p&gt;With the app suspended in the background instead of closed, the picture changes: a queued call was saved by&lt;br&gt;
JavaScript in 4 ms, because the runtime was still in memory. So the queue isn't wrong. It's only unreliable when&lt;br&gt;
the app has been closed, which is exactly when an assistant is most useful.&lt;/p&gt;
&lt;h2&gt;
  
  
  The bug: two copies of SQLite in one app
&lt;/h2&gt;

&lt;p&gt;The Swift design has a trap, and I walked straight into it.&lt;/p&gt;

&lt;p&gt;My first &lt;code&gt;TaskStore.swift&lt;/code&gt; opened the database with &lt;code&gt;import SQLite3&lt;/code&gt;, the system library, and it worked. Then I&lt;br&gt;
added "Milk" in the app, ran "Today's Tasks" from Shortcuts, and the result card said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You have nothing left to do today.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Swift and JavaScript were reading the same file, &lt;code&gt;Documents/SQLite/tasks.db&lt;/code&gt;. On disk the file had no rows and no&lt;br&gt;
WAL file. But the app process still had &lt;code&gt;tasks.db-wal&lt;/code&gt; open: the file had been deleted while expo-sqlite was using&lt;br&gt;
it. After restarting the app, "Milk" was gone for good.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: expo-sqlite ships its own SQLite.&lt;/strong&gt; expo-sqlite compiles SQLite 3.53.3 into your app and renames every function to &lt;code&gt;exsqlite3_*&lt;/code&gt;, so it can't clash with the system's SQLite (3.54.0 in the iOS 27 SDK). That also guarantees there are two separate copies in one process. SQLite's locks are POSIX locks, which belong to the whole process: one copy can't see the other's locks, and a &lt;code&gt;close()&lt;/code&gt; in one copy cancels the locks the other holds. So the system copy acted as if it were the only connection, and when it closed, the WAL file holding JavaScript's writes was deleted. SQLite's &lt;a href="https://www.sqlite.org/howtocorrupt.html" rel="noopener noreferrer"&gt;How To Corrupt An SQLite Database File&lt;/a&gt; lists exactly this: "multiple copies of SQLite linked into the same application".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The fix is to use expo-sqlite's copy from Swift. The ExpoSQLite pod exposes its header as a Swift module, so it's&lt;br&gt;
an import and a prefix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Don't `import SQLite3`: that's a second copy, with its own locks.&lt;/span&gt;
&lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ExpoSQLite&lt;/span&gt;

&lt;span class="nf"&gt;exsqlite3_open_v2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;databaseURL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;SQLITE_OPEN_READWRITE&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="no"&gt;SQLITE_OPEN_CREATE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;exsqlite3_busy_timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// JavaScript may hold the write lock&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the change, the app binary no longer links &lt;code&gt;libsqlite3.dylib&lt;/code&gt; at all (&lt;code&gt;otool -L&lt;/code&gt; shows nothing), the WAL file&lt;br&gt;
survives Swift closing its connection, and the same shortcut answered "You have one task left: Milk." The evidence,&lt;br&gt;
with the file listings, is in the repo.&lt;/p&gt;

&lt;p&gt;The fix has a cost a reviewer should see. &lt;code&gt;exsqlite3_*&lt;/code&gt; isn't a public API; it's how expo-sqlite builds SQLite&lt;br&gt;
today, and a future version could change it. Pin expo-sqlite, and add a CI check that fails if the app links&lt;br&gt;
&lt;code&gt;libsqlite3.dylib&lt;/code&gt; again. Swift now also writes to the &lt;code&gt;tasks&lt;/code&gt; table, so the schema is known in two languages. In&lt;br&gt;
the lab both sides create the table if it's missing; in a real app I'd let JavaScript own migrations and have Swift&lt;br&gt;
check &lt;code&gt;PRAGMA user_version&lt;/code&gt; before it writes.&lt;/p&gt;

&lt;p&gt;The same trap applies to any native code that touches a database your JavaScript owns: an App Intent, a widget, a&lt;br&gt;
notification extension, a background task. Before you write to it from Swift or Kotlin, check which SQLite your&lt;br&gt;
JavaScript library uses.&lt;/p&gt;
&lt;h2&gt;
  
  
  Finding a task: entities that read the database
&lt;/h2&gt;

&lt;p&gt;"Complete &lt;em&gt;buy milk&lt;/em&gt;" needs the system to find the task first. That's an &lt;code&gt;AppEntity&lt;/code&gt; with a query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;TaskQuery&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;EntityStringQuery&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;entities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;identifiers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;TaskEntity&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="nc"&gt;TaskStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;identifiers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TaskEntity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;init&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;suggestedEntities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;TaskEntity&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="nc"&gt;TaskStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;openTasks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TaskEntity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;init&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// entities(matching:) filters suggestedEntities() by title&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;expo-app-intents&lt;/code&gt; also has an entity catalog: JavaScript publishes records with &lt;code&gt;setEntityCatalogAsync&lt;/code&gt;, and&lt;br&gt;
Swift reads them. I didn't use it here, because the catalog can only be written from JavaScript. A task that the&lt;br&gt;
Swift design just added wouldn't be in it until the app next opened. Reading the database directly keeps one source&lt;br&gt;
of truth, now that Swift and JavaScript share it safely.&lt;/p&gt;

&lt;p&gt;The payoff showed up in the Shortcuts app. After the app called &lt;code&gt;refreshShortcutsAsync()&lt;/code&gt;, a parameterized "Milk"&lt;br&gt;
shortcut appeared, and tapping it answered "Marked Milk as done." without opening the app.&lt;/p&gt;
&lt;h2&gt;
  
  
  Write descriptions for the model, not for a person
&lt;/h2&gt;

&lt;p&gt;The strings you put on an intent are the prompt. Siri and Apple Intelligence read the title, the description and&lt;br&gt;
the parameter titles to decide whether your action fits what the user asked; on Android, Gemini reads the KDoc. This&lt;br&gt;
lab's descriptions say what the action does and what it doesn't:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;IntentDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Adds a task to today's list without opening the app."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;IntentDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Adds a task to today's list the next time the app runs."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same rules as for an MCP tool apply. Say when to use the action, name the object it works on, and be honest&lt;br&gt;
about side effects such as opening the app. I didn't measure how wording changes what the assistant picks; on the&lt;br&gt;
simulator there's no assistant to ask.&lt;/p&gt;
&lt;h2&gt;
  
  
  Phrases, and their limits
&lt;/h2&gt;

&lt;p&gt;App Shortcut phrases are compiled at build time, like the intents. A few rules from the library and Apple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every phrase must include &lt;code&gt;\(.applicationName)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A phrase can include at most one parameter, and only an entity or enum. "Add &lt;em&gt;buy milk&lt;/em&gt; in Lab Tasks" can't put
free text in the phrase. The expo-app-intents docs say a required parameter left out of the phrase is collected
with a follow-up question; I couldn't check that, because the simulator's Shortcuts app didn't show the prompt.&lt;/li&gt;
&lt;li&gt;An app can have at most 10 App Shortcuts. My lab used 6.&lt;/li&gt;
&lt;li&gt;An OTA update can't add or change any of this. New intents or phrases mean a new binary.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What I could and couldn't test on the simulator
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;App Shortcuts run on the iOS 27.0 release simulator.&lt;/strong&gt; They didn't on 26.5 through 27.0 beta 2
(&lt;a href="https://developer.apple.com/forums/thread/836585" rel="noopener noreferrer"&gt;FB23504349&lt;/a&gt;). If you're stuck on an older Xcode, this is
why.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The simulator's Shortcuts app didn't show the "Title?" prompt&lt;/strong&gt; for a shortcut with a text parameter, so the
measured runs used three lab-only shortcuts that call the same code with a fixed title.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Result cards sometimes appeared late&lt;/strong&gt;, after the next app came to the front. Don't treat the card as the end
of the run; my timings come from the database and from logs written inside &lt;code&gt;perform()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not exercised:&lt;/strong&gt; a duplicate delivery. The handler is written to be safe to replay (the invocation ID is the
task ID), but I never forced the queue to deliver the same call twice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not tested:&lt;/strong&gt; real Siri voice, Apple Intelligence on screen (&lt;code&gt;AppEntityView&lt;/code&gt;), and Spotlight indexing. All need
a device.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Android: AppFunctions, from the docs
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Not run yet.&lt;/strong&gt; Everything in this section comes from Android's documentation and from reading the expo-sqlite source. I haven't built or run it. The Android half of the lab (one AppFunction in the same Expo app, run on an Android 16 emulator through &lt;code&gt;adb&lt;/code&gt;) is next, and I'll update this post with what it finds.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;AppFunctions is the Android version of the same idea. An app declares typed functions, Android indexes them from a&lt;br&gt;
generated XML schema, and an authorised caller (Gemini, or another app holding &lt;code&gt;EXECUTE_APP_FUNCTIONS&lt;/code&gt;) runs them&lt;br&gt;
without opening the app.&lt;br&gt;
Google describes it as letting apps "behave like on device MCP servers". It needs Android 16 (API 36) and the&lt;br&gt;
&lt;code&gt;androidx.appfunctions&lt;/code&gt; Jetpack library, which is at 1.0.0-alpha13 (October 7, 2026).&lt;/p&gt;

&lt;p&gt;I couldn't find a React Native or Expo wrapper for it, so for now a React Native app needs its own small native&lt;br&gt;
module. The function itself is plain Kotlin, read by a KSP compiler plugin at build time, so like iOS you can't&lt;br&gt;
declare it from JavaScript. Adapted from Google's task example (not compiled; &lt;code&gt;Task&lt;/code&gt; is your own&lt;br&gt;
&lt;code&gt;@AppFunctionSerializable&lt;/code&gt; result type):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@RequiresApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nd"&gt;@AppFunctionServiceEntryPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;serviceName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"TaskAppFunctionService"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;appFunctionXmlFileName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"task_app_function_service"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BaseTaskAppFunctionService&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AppFunctionService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/**
   * Adds a task to today's list.
   *
   * @param params The title of the task to add.
   */&lt;/span&gt;
  &lt;span class="nd"&gt;@AppFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isDescribedByKDoc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;addTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AddTaskParams&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;withContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Dispatchers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Runs in Kotlin. Your JavaScript may not be running.&lt;/span&gt;
    &lt;span class="no"&gt;TODO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"save the task"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@AppFunctionSerializable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isDescribedByKDoc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AddTaskParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The KDoc is the description the model reads, the same role as an App Intent's &lt;code&gt;description&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The same three designs apply.&lt;/strong&gt; The function runs in a Kotlin service, so the question from the iOS half comes&lt;br&gt;
straight back: do the work natively, queue it for JavaScript, or bring the app forward. Unlike iOS, there's no&lt;br&gt;
library queue yet; you'd write one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The same SQLite trap is there in principle.&lt;/strong&gt; expo-sqlite's Android build compiles its own &lt;code&gt;sqlite3.c&lt;/code&gt; into the&lt;br&gt;
library it ships (&lt;code&gt;android/CMakeLists.txt&lt;/code&gt; in the package). Android's &lt;code&gt;android.database.sqlite&lt;/code&gt; uses the platform's&lt;br&gt;
SQLite. Writing JavaScript's database from Kotlin with the platform API would put two copies of SQLite in one&lt;br&gt;
process, the setup that lost data on iOS. I haven't reproduced it on Android; the lab will check.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can test without Gemini.&lt;/strong&gt; The docs point to &lt;code&gt;adb shell cmd app_function&lt;/code&gt; for checking registration, reading&lt;br&gt;
the descriptions the model will see, and running a function on a device or emulator, starting with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;adb shell cmd app_function list-app-functions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Gemini itself is gated.&lt;/strong&gt; Google's docs say that as of May 2026 the Gemini integration is "in a private preview&lt;br&gt;
with trusted testers", with an early access form for select apps. You can ship the functions now; most apps can't yet&lt;br&gt;
watch Gemini call them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who can call your app, and what they can do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Anything an intent does can be triggered without your UI ever appearing. For destructive actions (delete,
pay), ask for confirmation in &lt;code&gt;perform()&lt;/code&gt; before doing the work.&lt;/li&gt;
&lt;li&gt;Validate every parameter in Swift and again in JavaScript. A saved shortcut can replay old parameter values, and
an ID can point to a record that was deleted since.&lt;/li&gt;
&lt;li&gt;Anything you put in the entity catalog or the Spotlight index is visible to the system. Sync titles, not
private notes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to ship now
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;If Siri should finish the job, do it natively.&lt;/strong&gt; The queue is fine for "sync this later", but with the app
closed it won't run your JavaScript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Share one SQLite copy.&lt;/strong&gt; If JavaScript uses expo-sqlite, Swift must use &lt;code&gt;exsqlite3_*&lt;/code&gt; through
&lt;code&gt;import ExpoSQLite&lt;/code&gt;, never &lt;code&gt;import SQLite3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make every handler safe to replay&lt;/strong&gt;, and remove a pending call only after its work succeeded.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;expo-app-intents&lt;/code&gt; is alpha&lt;/strong&gt;, and its docs warn of frequent breaking changes. Pin the version.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can Siri call a React Native app that isn't running?
&lt;/h3&gt;

&lt;p&gt;Yes, but the intent's &lt;code&gt;perform()&lt;/code&gt; runs in Swift. &lt;code&gt;expo-app-intents&lt;/code&gt; queues the call for JavaScript without&lt;br&gt;
starting it, so with the app closed a queued task wasn't saved until the app was next opened. Doing the work in&lt;br&gt;
Swift saved it in 5–23 ms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why did my App Intent lose data that JavaScript had saved with expo-sqlite?
&lt;/h3&gt;

&lt;p&gt;expo-sqlite bundles its own copy of SQLite. Writing the same database file from Swift with the system SQLite&lt;br&gt;
deleted the WAL file and lost a task. Use &lt;code&gt;import ExpoSQLite&lt;/code&gt; and the &lt;code&gt;exsqlite3_*&lt;/code&gt; functions so both sides share&lt;br&gt;
one copy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does the same apply to Android's AppFunctions?
&lt;/h3&gt;

&lt;p&gt;AppFunctions have the same shape: Kotlin runs first, and expo-sqlite ships its own SQLite on Android too. That&lt;br&gt;
comes from the docs and the expo-sqlite source; I haven't run the Android half yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;App Intents run in Swift. expo-app-intents queues the call for JavaScript, but doesn't start it.&lt;/li&gt;
&lt;li&gt;With the app closed: Swift saved the task in 5–23 ms, the queue waited until the app was opened, and opening the app took about 2 s.&lt;/li&gt;
&lt;li&gt;expo-sqlite bundles its own SQLite. Writing the same file with the system SQLite deleted the WAL and lost data.&lt;/li&gt;
&lt;li&gt;Use import ExpoSQLite and exsqlite3_* from Swift, so both sides share one copy.&lt;/li&gt;
&lt;li&gt;App Shortcuts run on the iOS 27.0 simulator, but test real Siri on a device.&lt;/li&gt;
&lt;li&gt;Android's AppFunctions raise the same questions: Kotlin runs first, and expo-sqlite ships its own SQLite there too.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about React Native in practice, measured and with public code, at &lt;a href="https://www.praveensingh.co.in/blog" rel="noopener noreferrer"&gt;praveensingh.co.in/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>ios</category>
      <category>ai</category>
      <category>expo</category>
    </item>
    <item>
      <title>Bareship: an offline-first React Native template for teams and AI agents</title>
      <dc:creator>Praveen Singh</dc:creator>
      <pubDate>Thu, 22 Oct 2026 15:39:25 +0000</pubDate>
      <link>https://dev.to/praveensingh/bareship-an-offline-first-react-native-template-for-teams-and-ai-agents-3ihi</link>
      <guid>https://dev.to/praveensingh/bareship-an-offline-first-react-native-template-for-teams-and-ai-agents-3ihi</guid>
      <description>&lt;p&gt;&lt;strong&gt;Bareship is a free, MIT-licensed template for bare React Native 0.87 apps.&lt;/strong&gt; One command, &lt;code&gt;npx create-bareship Acme&lt;/code&gt;, gives you an iOS and Android app where a like or an edit made offline is saved, survives a restart and is sent once when the phone reconnects; where the folder rules are checked by ESLint instead of code review; and where Claude Code, Cursor or Copilot get the same rules as your team. It runs with no backend, Firebase project or Apple account until you need them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffacw6kx1u4yvzddg3crq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffacw6kx1u4yvzddg3crq.gif" alt="On Android: airplane mode on, a like is saved and marked " width="480" height="853"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why another template?
&lt;/h2&gt;

&lt;p&gt;Every new React Native app I've started began the same way: a week or two rebuilding the plumbing before the first real feature. A queue for writes made without signal, somewhere safe for the auth token, folder rules everyone agrees on and nobody checks. Each time I built them a little differently, and each time the gaps showed up later, in a bug report from a user with a bad connection or in a feature folder that had quietly started importing from three others. I wanted to make those decisions once, properly, and start from there.&lt;/p&gt;

&lt;p&gt;Most starters get you to a running screen fast. The parts that cost time later are the ones a demo never touches: what happens to a write when the phone has no signal, where the auth token lives, and whether the folder structure you agreed on in week one still holds in month six, with three developers and a coding agent all adding code. Bareship is my answer to those, decided once and written down.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens when the phone goes offline?
&lt;/h2&gt;

&lt;p&gt;Every write in the app picks one of four patterns, so a user always knows what became of what they did:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Without a connection&lt;/th&gt;
&lt;th&gt;Use it for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;The change appears at once and is sent later&lt;/td&gt;
&lt;td&gt;Low-stakes toggles&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;The change appears at once, marked "Waiting to sync"&lt;/td&gt;
&lt;td&gt;Likes, comments, edits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;The form is disabled, with a note saying why&lt;/td&gt;
&lt;td&gt;Sign-in, payments&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;D&lt;/td&gt;
&lt;td&gt;The content is replaced by an offline message&lt;/td&gt;
&lt;td&gt;Account deletion, checkout&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Queued writes are saved to disk, replayed in the order they were made after a restart, and carry one idempotency key for every attempt, so a write sent twice is applied once. A banner under the header counts the changes waiting to sync. A write that picks no pattern fails at once offline, so nothing is queued by accident.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules the build enforces
&lt;/h2&gt;

&lt;p&gt;The architecture is in the linter, not a wiki page. Layers import downward only, features can't reach into each other's files, text on screen must go through translations, and accessibility uses one set of ARIA props everywhere. ESLint and dependency-cruiser fail the check otherwise. When a rule is wrong for your app, you change it in one place and write down why: the decisions behind the template are kept as ADRs in the repo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Built for AI coding agents
&lt;/h2&gt;

&lt;p&gt;The repo ships an &lt;code&gt;AGENTS.md&lt;/code&gt;, its decision records and React Native agent skills, plus generators (&lt;code&gt;pnpm gen feature | screen | endpoint&lt;/code&gt;) that write a schema, API hooks, a mock, strings and a test the way the rest of the code does. An agent that follows them writes code that passes the same checks as your team's.&lt;/p&gt;

&lt;p&gt;I built much of Bareship with Claude Code, so these files were tested on an agent from the start: when it broke a rule, the fix went into the linter or &lt;code&gt;AGENTS.md&lt;/code&gt;, not into a comment on a pull request.&lt;/p&gt;

&lt;h2&gt;
  
  
  It runs with no accounts
&lt;/h2&gt;

&lt;p&gt;The dev build serves sample data from a mock backend inside the app, so you can sign in, scroll the feed and test offline mode on a simulator or a phone before any backend exists. Crashlytics, Analytics, Remote Config and push turn on when you add a Firebase file and fall back to logging without one. Tokens are stored in the Keychain and Keystore from day one.&lt;/p&gt;

&lt;p&gt;Also included: light and dark themes, English and Hindi (with right-to-left support you can switch on), deep links, force-update and maintenance screens, environments for dev, staging and prod, fastlane release lanes and a demo build you can install on a phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-bareship Acme
&lt;span class="nb"&gt;cd &lt;/span&gt;Acme
pnpm android   &lt;span class="c"&gt;# or: pnpm ios&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;create-bareship&lt;/code&gt; checks your tools first, asks for a bundle id and display name, installs everything and makes the first commit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvr4a4tu2u8ttmwslswl3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvr4a4tu2u8ttmwslswl3.gif" alt="npx create-bareship Acme in a terminal, then pnpm android, then the Acme app running on an Android emulator (sped up)" width="720" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sped up: the real run took 1 min 15 s to create the app. The full-quality video is &lt;a href="https://www.praveensingh.co.in/blog/introducing-bareship#try-it" rel="noopener noreferrer"&gt;on my blog&lt;/a&gt;.&lt;/em&gt; The first Android build compiles the native libraries and takes a while (about 20 minutes on my 8 GB M1, a few minutes on a faster machine); builds after that are quick.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/psingh2907" rel="noopener noreferrer"&gt;
        psingh2907
      &lt;/a&gt; / &lt;a href="https://github.com/psingh2907/bareship" rel="noopener noreferrer"&gt;
        bareship
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Production-ready, offline-first bare React Native template for teams and AI agents. Create an app: npx create-bareship MyApp
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;Bareship is at 0.3.2. Next on the list: turning CI back on in the repository, and a series of posts on how the pieces work, starting with the offline queue and idempotency keys. If it saves you a week, a star on GitHub helps other people find it, and issues are the best way to tell me what's missing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npx create-bareship Acme&lt;/code&gt; creates a bare React Native 0.87 app for iOS and Android in one command.&lt;/li&gt;
&lt;li&gt;Each write picks one of four offline patterns; queued writes survive a restart and are applied once.&lt;/li&gt;
&lt;li&gt;Layers, feature boundaries, translations and accessibility are enforced by ESLint and dependency-cruiser.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AGENTS.md&lt;/code&gt;, ADRs, skills and generators give AI coding agents the same rules as your team.&lt;/li&gt;
&lt;li&gt;It runs with no backend, Firebase or Apple account; you add each service when you need it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Docs: &lt;a href="https://bareship.praveensingh.co.in" rel="noopener noreferrer"&gt;bareship.praveensingh.co.in&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>opensource</category>
      <category>mobile</category>
      <category>ai</category>
    </item>
    <item>
      <title>On-device AI in React Native, late 2026: one AI SDK call, two engines, measured</title>
      <dc:creator>Praveen Singh</dc:creator>
      <pubDate>Mon, 12 Oct 2026 04:55:34 +0000</pubDate>
      <link>https://dev.to/praveensingh/on-device-ai-in-react-native-late-2026-one-ai-sdk-call-two-engines-measured-5455</link>
      <guid>https://dev.to/praveensingh/on-device-ai-in-react-native-late-2026-one-ai-sdk-call-two-engines-measured-5455</guid>
      <description>&lt;p&gt;&lt;strong&gt;At a glance&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Problem: Run an LLM inside a React Native app, with no server and no API key&lt;/li&gt;
&lt;li&gt;Fix: Two on-device engines behind one AI SDK call, plus a model picker that checks each engine actually works&lt;/li&gt;
&lt;li&gt;Result: 20 vs 2 (valid structured outputs out of 20: Apple's guided generation vs a 1B ExecuTorch model)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; On-device AI in React Native is practical now, but the two engines suit different jobs. Use Apple's Foundation Models when the device has it: no download, and guided generation returned valid structured output 20 times out of 20. Use ExecuTorch for everything else, but not for structured output from a 1B model: only 2 of 20 responses matched my schema. Keep a cloud fallback, and check that each engine really works rather than trusting its availability flag.&lt;/p&gt;

&lt;p&gt;React Native got a lot of AI news this year. WWDC26 expanded Apple's Foundation Models framework (image input, Private Cloud Compute, third-party models behind the same API). Software Mansion rewrote ExecuTorch for 0.10 with Core ML, MLX and Vulkan backends. Callstack's &lt;a href="https://github.com/callstackincubator/ai" rel="noopener noreferrer"&gt;&lt;code&gt;react-native-ai&lt;/code&gt;&lt;/a&gt; put Apple's model, llama.rn, MLC and Gemini Nano behind the Vercel AI SDK. An &lt;code&gt;expo-ai&lt;/code&gt; package is in review in the Expo repo.&lt;/p&gt;

&lt;p&gt;Release posts tell you what's possible. I wanted to know what it takes, so I built one small React Native 0.87 app that calls both engines through the same &lt;code&gt;streamText&lt;/code&gt; / &lt;code&gt;generateObject&lt;/code&gt; code, and measured them on the same tasks.&lt;/p&gt;

&lt;p&gt;Everything is in &lt;a href="https://github.com/psingh2907/rn-on-device-ai-lab" rel="noopener noreferrer"&gt;a public repo&lt;/a&gt;: code, raw results and the failures.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The setup, and what I couldn't measure.&lt;/strong&gt; React Native 0.87.1, AI SDK 6, &lt;code&gt;@react-native-ai/apple&lt;/code&gt; 0.12.0, &lt;code&gt;react-native-executorch&lt;/code&gt; 0.10.4 running Llama 3.2 1B. An Apple M1 with 8 GB of memory, the iPhone 17 simulator on iOS 26.3, &lt;strong&gt;no physical devices&lt;/strong&gt;. ExecuTorch ran in the app on the simulator. Apple's model wouldn't run in the simulator (more below), so I ran the same tasks against it from Swift on the Mac. These are Mac numbers, not iPhone numbers: use them to compare the two engines, not to predict latency on a phone. Gemini Nano on Android needs a supported phone, so it's covered from the docs only.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The two tasks
&lt;/h2&gt;

&lt;p&gt;Five store-audit notes, written the way an auditor types them on a phone:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Freezer 2 door seal torn, temp reading -12 instead of -18. Aisle 4 lights flickering. Fire exit at the back blocked by two pallets of water.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Summary:&lt;/strong&gt; streamed, two sentences, most urgent issue first. I measured time to first text and total time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Checklist:&lt;/strong&gt; structured output, validated against a Zod schema with &lt;code&gt;generateObject&lt;/code&gt;. One item per issue, each with an area, an issue and a severity of &lt;code&gt;low&lt;/code&gt;, &lt;code&gt;medium&lt;/code&gt; or &lt;code&gt;high&lt;/code&gt;. 10 runs per engine, per run of the benchmark.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  One call site for both engines
&lt;/h2&gt;

&lt;p&gt;Apple's model already has an AI SDK provider. ExecuTorch doesn't, so I wrote a small adapter. Version 0.10 makes this easier: below the &lt;code&gt;useLLMChatSession&lt;/code&gt; hook it exposes the runner and the model's chat template as separate pieces.&lt;/p&gt;

&lt;p&gt;I didn't use the chat session itself. It keeps a growing conversation in the model's cache, which suits a chat screen but not a one-off &lt;code&gt;generateText&lt;/code&gt; call. The adapter resets the runner and renders the AI SDK prompt from scratch on every call:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/lab/executorchModel.ts (excerpt)&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LanguageModelV3CallOptions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;onToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;responseFormat&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;responseFormat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;toMessages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// AI SDK prompt -&amp;gt; chat messages&lt;/span&gt;
  &lt;span class="nx"&gt;runner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// stateless: no history from earlier calls&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;preprocessor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;addGenPrompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="nx"&gt;preprocessor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;genConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;maxNewTokens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maxOutputTokens&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;temperature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;generateAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;runner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;genConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stopTokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;onToken&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// runs on a worklet thread&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;doGenerate&lt;/code&gt; and &lt;code&gt;doStream&lt;/code&gt; wrap that, and after that the calling code is the same for both engines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;streamText&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;system&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;maxOutputTokens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;160&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generateObject&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;checklistSchema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;system&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's one difference the code can't hide. Apple's model fills the schema through &lt;strong&gt;guided generation&lt;/strong&gt;: the framework restricts what the model can output to fit the type. ExecuTorch has no equivalent here, so the adapter puts the schema in the prompt and hopes. That difference decided the structured-output results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting it to build took seven fixes
&lt;/h2&gt;

&lt;p&gt;None of these are hard, but each one stops the app from building or running, and I didn't find any of them in the docs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;iOS build fails: &lt;code&gt;unknown type name 'RCTCxxBridge'&lt;/code&gt; in &lt;code&gt;RnExecutorch.mm&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;React Native 0.87 removed it. Patch the module to install its JSI bindings through &lt;code&gt;RCTTurboModuleWithJSIBindings&lt;/code&gt; (&lt;a href="https://github.com/psingh2907/rn-on-device-ai-lab/blob/main/patches/react-native-executorch%2B0.10.4.patch" rel="noopener noreferrer"&gt;patch&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CocoaPods: "required a higher minimum deployment target"&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;platform :ios, '17.0'&lt;/code&gt; in the &lt;code&gt;Podfile&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Metro: "Export namespace should be first transformed"&lt;/td&gt;
&lt;td&gt;Add &lt;code&gt;@babel/plugin-transform-export-namespace-from&lt;/code&gt;, the &lt;strong&gt;v7&lt;/strong&gt; release (v8 needs Babel 8)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ExecuTorch native calls fail&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;react-native-worklets/plugin&lt;/code&gt;, last in the Babel plugins&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Property 'TextDecoder' doesn't exist&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Polyfills for the AI SDK on Hermes (below)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;ai@latest&lt;/code&gt; installs 7.x&lt;/td&gt;
&lt;td&gt;Pin &lt;code&gt;ai@6&lt;/code&gt;: the React Native AI providers implement the v6 spec&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;npm 11 skips ExecuTorch's postinstall&lt;/td&gt;
&lt;td&gt;Approve it after reading it: it downloads the native libraries from the project's GitHub releases&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The polyfills:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/polyfills.ts&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;web-streams-polyfill/polyfill&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ReadableStream, TransformStream&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fast-text-encoding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// TextDecoder&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;TextDecoderStream&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TextEncoderStream&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@stardazed/streams-text-encoding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;structuredClone&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@ungap/structured-clone&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;globalThis&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TextEncoderStream&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="nx"&gt;TextEncoderStream&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TextDecoderStream&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="nx"&gt;TextDecoderStream&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;structuredClone&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: Use the global ReadableStream in your adapter.&lt;/strong&gt; My first streaming run died with "First parameter has member 'readable' that is not a ReadableStream". I had imported &lt;code&gt;ReadableStream&lt;/code&gt; from &lt;code&gt;web-streams-polyfill&lt;/code&gt;, which is a different class from the global one the polyfill installs, and the AI SDK checks against the global. Build streams with &lt;code&gt;globalThis.ReadableStream&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gotcha: ExecuTorch sends download analytics by default.&lt;/strong&gt; Version 0.10 reports anonymous download events to Software Mansion unless you call &lt;code&gt;setTelemetryEnabled(false)&lt;/code&gt;. That's easy to miss, and it matters if you picked on-device AI for privacy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Two things that failed on the simulator
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Apple's model said it was available, then failed every call.&lt;/strong&gt; &lt;code&gt;apple.isAvailable()&lt;/code&gt; returned &lt;code&gt;true&lt;/code&gt; in the iOS 26.3 simulator, and all 30 calls across two runs failed with &lt;code&gt;GenerationError error -1&lt;/code&gt;. The simulator log had the real reason: the model catalog had no assets (&lt;code&gt;UnifiedAssetFramework Code=5000&lt;/code&gt;). The same model worked from Swift on the Mac, which runs macOS 26.6, so my guess is a mismatch between the simulator runtime and the Mac's model assets. Either way, the availability flag isn't proof.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The MLX build of the model downloaded, then wouldn't load.&lt;/strong&gt; I picked &lt;code&gt;LLAMA3_2_1B.MLX_INT4&lt;/code&gt; to compare against the CPU backend. It downloaded all 1.18 GB, then failed with &lt;code&gt;Error::NotFound&lt;/code&gt;. The podspec explains it: the MLX backend is only linked into device builds, because the simulator SDK lacks the Metal APIs it needs. &lt;code&gt;.DEFAULT&lt;/code&gt; would have avoided this, because it only picks backends that are actually linked into the build.&lt;/p&gt;

&lt;p&gt;Both lead to the same rule, and it's built into the model picker below: &lt;strong&gt;check that an engine works with a real call, and use the library's defaults rather than hard-coding a variant.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Speed: similar once warm
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;ExecuTorch, Llama 3.2 1B (simulator)&lt;/th&gt;
&lt;th&gt;Apple Foundation Models (Mac)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Download before first use&lt;/td&gt;
&lt;td&gt;1.14 GB, 6 min 12 s&lt;/td&gt;
&lt;td&gt;none, part of the OS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Load from disk&lt;/td&gt;
&lt;td&gt;4.4–5.3 s&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;First call, time to first text&lt;/td&gt;
&lt;td&gt;0.6–0.8 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;9.7–19.2 s&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Later calls, time to first text (median)&lt;/td&gt;
&lt;td&gt;579 ms&lt;/td&gt;
&lt;td&gt;580 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Later calls, full summary (median)&lt;/td&gt;
&lt;td&gt;2.5 s&lt;/td&gt;
&lt;td&gt;2.9 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Generation speed (median)&lt;/td&gt;
&lt;td&gt;43 tokens/s&lt;/td&gt;
&lt;td&gt;not reported&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;App memory while generating (median)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;907 MB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;not in the app's process&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Once both were warm, they were close. The differences are at the edges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ExecuTorch's cost is up front.&lt;/strong&gt; A 1.14 GB download on first use, then about 5 s to load the model on each launch. While generating, the app used about 900 MB of memory, which matters on phones that kill background apps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apple's cost is the first call.&lt;/strong&gt; That first call took 10–19 s on this Mac, and later calls took about half a second. The model runs in a system process, so it adds nothing to your app's memory, and there's nothing to download.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How I measured.&lt;/strong&gt; Two full runs per engine: 5 summaries and 10 checklists each, plus a third set of 10 checklists for the prompt fix below. The first call of each run is reported separately. Memory is the app process's resident size, sampled on the Mac at each result. The Mac was swapping during the runs (5.6 of 6 GB of swap in use), which hurts the Apple numbers most. The raw results and the summary script are in the repo's &lt;code&gt;metrics&lt;/code&gt; and &lt;code&gt;scripts&lt;/code&gt; folders.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;@react-native-ai/apple&lt;/code&gt; reports zero tokens to the AI SDK, so its token counts and tokens per second are missing. Compare time to first text and total time instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Structured output: 2 out of 20 vs 20 out of 20
&lt;/h2&gt;

&lt;p&gt;This is the biggest difference between the two engines:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Checklist output that passed the Zod schema&lt;/th&gt;
&lt;th&gt;Valid&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ExecuTorch, schema in the prompt&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;2 / 20&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ExecuTorch, example in the prompt, plus a repair step&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;6 / 10&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Apple, guided generation&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;20 / 20&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The 1B model failed in three ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;It returned the schema.&lt;/strong&gt; In 5 of the 9 failures in one run, it replied with the JSON Schema itself (&lt;code&gt;{"$schema": "http://json-schema.org/draft-07/schema#", ...}&lt;/code&gt;) instead of filling it in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wrong case:&lt;/strong&gt; &lt;code&gt;"severity": "High"&lt;/code&gt; where the schema says &lt;code&gt;"high"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not JSON at all:&lt;/strong&gt; a bulleted list wrapped in braces.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two cheap changes raised the pass rate from 1 in 10 to 6 in 10 in the same run. Show an example instead of the schema, and lower-case the enum values before validation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generateObject&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;checklistSchema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// The adapter puts this example in the prompt instead of the JSON Schema.&lt;/span&gt;
  &lt;span class="na"&gt;providerOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;executorch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;jsonExample&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"items":[{"area":"Aisle 2","issue":"Spilled milk","severity":"high"}]}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;experimental_repairText&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/"&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;low|medium|high&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;"/gi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6 out of 10 still isn't good enough to ship, and passing the schema doesn't mean the content is right. I read every valid checklist from the 1B model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Two of the six copied my example into the store's checklist: "Aisle 2: Spilled milk on floor" was never in the note.&lt;/li&gt;
&lt;li&gt;Fields got mixed up: "Back fire exit: Expired yoghurt found in dairy fridge".&lt;/li&gt;
&lt;li&gt;Items were duplicated, and every item, in every valid checklist, was marked high.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apple's 20 checklists listed every issue in each note, in sensible areas, and never invented one. It rated a few minor issues too high (a frozen checkout scanner as high), but the fire, rodent and food-safety issues were high every time.&lt;/p&gt;

&lt;p&gt;Neither engine was good at the summaries. The 1B model opened every one with "Here is a two-sentence summary", then often wrote three or four. It also misread the notes: once it said the torn freezer seal was blocking the fire exit, once that a leaking roof was "not an issue". Apple's summaries were shorter (177 characters against 396), but half came back as Markdown bullet lists rather than two sentences. One left out the wet floor, and another ranked the frozen scanner above expired food.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If your feature needs structured output, a 1B model in your app isn't enough.&lt;/strong&gt; Use the system model, a larger downloaded model (Llama 3.2 3B is in ExecuTorch's catalog), or the cloud.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing a model at runtime
&lt;/h2&gt;

&lt;p&gt;Here's the picker the lab uses. The order is fixed: Apple's model if it really works, then a downloaded model if the user agreed to the download, then the cloud. The result is cached for the session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;src/lab/router.ts&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// apple.isAvailable() said true in the simulator while every call failed,&lt;/span&gt;
&lt;span class="c1"&gt;// so it's only a first filter. A one-token call is the real check.&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;appleWorks&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Platform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OS&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;apple&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generateText&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;apple&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Reply with OK.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;maxOutputTokens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;pickModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cloud&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LanguageModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;allowDownload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;}):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;appleWorks&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;apple&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;on-device (Apple)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allowDownload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// DEFAULT only picks backends linked into this build.&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;et&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createExecutorchModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;llama-3.2-1b&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;LLAMA3_2_1B&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DEFAULT&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;et&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;et&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;on-device (downloaded model)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;cloud&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cloud&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;})());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;where&lt;/code&gt; is for the UI. If people chose your feature because their text stays on the phone, tell them when it doesn't. That applies to the cloud fallback, and to Apple's Private Cloud Compute when iOS 27 sends a request there.&lt;/p&gt;

&lt;p&gt;This code is type-checked but not benchmarked; the lab measured each engine on its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Android: Gemini Nano, from the docs
&lt;/h2&gt;

&lt;p&gt;I couldn't test this one: Gemini Nano needs a supported Android 14+ phone, and an emulator won't do. On paper it fits the same pattern. &lt;a href="https://www.react-native-ai.dev/docs/adk/getting-started" rel="noopener noreferrer"&gt;&lt;code&gt;@react-native-ai/adk&lt;/code&gt;&lt;/a&gt; is another AI SDK provider, so it would be one more branch in &lt;code&gt;pickModel&lt;/code&gt;. Its availability check comes in steps: &lt;code&gt;isNanoSupported()&lt;/code&gt; (can this phone run it?), &lt;code&gt;isAvailable()&lt;/code&gt; (is it ready?) and &lt;code&gt;prepareNano()&lt;/code&gt;. Given what happened with Apple's flag, I'd still add a probe call. ExecuTorch also runs on Android, using Vulkan for the GPU, so the downloaded-model branch carries over unchanged.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to use, and when
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use Apple's Foundation Models first on iOS.&lt;/strong&gt; There's nothing to download, it doesn't use your app's memory, and guided generation makes structured output reliable. Expect a slow first call, so warm the model up before the user needs it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use ExecuTorch when there's no system model&lt;/strong&gt;, for short free-text tasks where a person reads the result: rewording, suggestions, drafts. Check its output before you act on it. Ask before the 1 GB download, show progress, and turn off telemetry. Don't depend on a 1B model for JSON.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep a cloud fallback&lt;/strong&gt;, and label it in the UI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Watch &lt;code&gt;expo-ai&lt;/code&gt;.&lt;/strong&gt; It's in review with an Apple provider, streaming and tool calls. If it lands, most of the setup fixes above become Expo's problem rather than yours.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Put both engines behind the AI SDK so the calling code stays the same; ExecuTorch needs a small adapter.&lt;/li&gt;
&lt;li&gt;Pin ai@6 for the React Native AI providers, and add stream, TextDecoder and structuredClone polyfills for Hermes.&lt;/li&gt;
&lt;li&gt;ExecuTorch 0.10.4 needs a one-file patch to build on React Native 0.87 iOS.&lt;/li&gt;
&lt;li&gt;Don't trust apple.isAvailable() alone: make a tiny probe call and cache the result.&lt;/li&gt;
&lt;li&gt;Use ExecuTorch's .DEFAULT variants; MLX variants download and then fail on the simulator.&lt;/li&gt;
&lt;li&gt;A 1B model returned schema-valid JSON 2 times in 20; an example prompt and a repair step got it to 6 in 10.&lt;/li&gt;
&lt;li&gt;Apple's guided generation returned valid output 20 times in 20.&lt;/li&gt;
&lt;li&gt;Turn off ExecuTorch telemetry, and show users when a request leaves the device.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about React Native in practice, measured and with public code, at &lt;a href="https://www.praveensingh.co.in/blog" rel="noopener noreferrer"&gt;praveensingh.co.in/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>ai</category>
      <category>mobile</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Giving your coding agent eyes on a React Native app: Argent vs agent-device, measured</title>
      <dc:creator>Praveen Singh</dc:creator>
      <pubDate>Fri, 09 Oct 2026 10:50:06 +0000</pubDate>
      <link>https://dev.to/praveensingh/giving-your-coding-agent-eyes-on-a-react-native-app-argent-vs-agent-device-measured-1blh</link>
      <guid>https://dev.to/praveensingh/giving-your-coding-agent-eyes-on-a-react-native-app-argent-vs-agent-device-measured-1blh</guid>
      <description>&lt;p&gt;&lt;strong&gt;At a glance&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Problem: Let a coding agent run, tap through and profile a React Native app by itself&lt;/li&gt;
&lt;li&gt;Fix: Argent or agent-device, each given alone to Claude Code, on three planted bugs&lt;/li&gt;
&lt;li&gt;Result: 12 / 12 (runs fully solved, by both tools; agent-device used about a fifth of the tokens)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; Both tools let a coding agent reproduce, fix, verify and profile real React Native bugs. Every one of the 12 scored runs got full marks. The difference is cost and setup. agent-device runs used about a fifth of the tokens and a third of the money, because it answers with compact text instead of a screenshot after every action. Argent's React profiler worked with no setup on React Native 0.87, while agent-device's needed a package installed and two project files patched first.&lt;/p&gt;

&lt;p&gt;Coding agents used to stop at "it compiles". In 2026 a set of tools lets them run the app, tap through it, read the screen and profile it. Two are built with React Native in mind: Software Mansion's &lt;a href="https://argent.swmansion.com/" rel="noopener noreferrer"&gt;Argent&lt;/a&gt; and Callstack's &lt;a href="https://github.com/callstack/agent-device" rel="noopener noreferrer"&gt;agent-device&lt;/a&gt;. Both claim to close the loop. I wanted to know what that looks like on a real app, and what it costs.&lt;/p&gt;

&lt;p&gt;So I planted three bugs in a small React Native 0.87 app and gave Claude Code the same bug reports twice: once with only Argent, once with only agent-device. Everything is in &lt;a href="https://github.com/psingh2907/rn-agent-sim-lab" rel="noopener noreferrer"&gt;a public repo&lt;/a&gt;: the app, the harness, the rubric, every transcript and every score.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The setup.&lt;/strong&gt; The store-audit app from my &lt;a href="https://www.praveensingh.co.in/blog/react-native-0-87-upgrade" rel="noopener noreferrer"&gt;0.87 upgrade post&lt;/a&gt;, on React Native 0.87.1 with FlashList, in the iPhone 17 simulator on an Apple M1 with 8 GB of memory. Argent 0.26.0 (its MCP server, skills and rules, as &lt;code&gt;argent init&lt;/code&gt; installs them) against agent-device 0.21.19 (its CLI, skills from &lt;code&gt;npx skills add&lt;/code&gt;, and the &lt;code&gt;CLAUDE.md&lt;/code&gt; text its docs recommend). Claude Code 2.1.42 in headless mode with &lt;code&gt;claude-sonnet-5-5&lt;/code&gt;, one session per run. Three tasks, two runs per tool per task, 12 scored runs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The three bugs
&lt;/h2&gt;

&lt;p&gt;Each run got one bug report, written the way a store auditor would send it, plus a line saying the app is installed and Metro is running. Nothing pointed at files or causes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reproduce:&lt;/strong&gt; "I tapped yes on 'Fire exit clear of obstructions'. When I scrolled down, other questions I never touched showed yes too." Each row kept its own copy of the answer in &lt;code&gt;useState&lt;/code&gt;, and FlashList recycles rows, so a recycled row shows the previous question's answer. The agent had to reproduce it in the app and explain it, without changing code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fix and verify:&lt;/strong&gt; "The yes/no buttons are missing on questions with long titles." The question text couldn't shrink, so long titles pushed the buttons off screen. The agent had to fix it and prove both long and short rows look right in the app.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; "Typing in the Notes box feels laggy." The note's state lived in the screen, so every keystroke re-rendered every visible row, and each row ran a slow keyword check (about 8 ms per row). The agent had to find out why with real measurements, fix it, and measure again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I wrote the &lt;a href="https://github.com/psingh2907/rn-agent-sim-lab/blob/main/harness/RUBRIC.md" rel="noopener noreferrer"&gt;scoring rubric&lt;/a&gt; and committed it before the first scored run: three points per task, and points that need evidence from the running app don't count if the agent only read the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making it a fair test took four fixes
&lt;/h2&gt;

&lt;p&gt;A comparison like this is only fair if each session sees exactly one tool. My machine has Argent installed globally, so that took more work than I expected:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;--setting-sources project&lt;/code&gt; still loaded my global &lt;code&gt;~/.claude/CLAUDE.md&lt;/code&gt; and rules, including Argent's. A probe session in the agent-device setup quoted Argent's tapping rule back to me&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;CLAUDE_CODE_DISABLE_CLAUDE_MDS=1&lt;/code&gt; and &lt;code&gt;CLAUDE_CODE_DISABLE_AUTO_MEMORY=1&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Argent's global skills are relative symlinks, so copying them into a plugin folder copied broken links&lt;/td&gt;
&lt;td&gt;Copy with &lt;code&gt;cp -RL&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;My lab's commit messages described the planted bugs, and agents can read &lt;code&gt;git log&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Agents work in a separate copy of the app with a single, history-free commit, reset between runs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One agent installed a package to profile, then removed it, leaving empty folders in &lt;code&gt;node_modules&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;npm prune&lt;/code&gt; and remove empty folders before each run&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each tool's skills went in through &lt;code&gt;--plugin-dir&lt;/code&gt;, its MCP config through &lt;code&gt;--strict-mcp-config&lt;/code&gt;, and its rules through &lt;code&gt;--append-system-prompt&lt;/code&gt;. The other tool's command was shadowed on &lt;code&gt;PATH&lt;/code&gt;. A probe run before the real ones confirmed that each session listed only its own tool.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: You can't start Claude Code from inside Claude Code.&lt;/strong&gt; Running &lt;code&gt;claude -p&lt;/code&gt; from an agent session fails with "Claude Code cannot be launched inside another Claude Code session". I started the runs from a separate terminal. The command-line tool also needs its own &lt;code&gt;claude auth login&lt;/code&gt;; being signed in to the desktop app isn't enough.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Both tools solved every task
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task&lt;/th&gt;
&lt;th&gt;Argent&lt;/th&gt;
&lt;th&gt;agent-device&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Reproduce&lt;/td&gt;
&lt;td&gt;6 / 6&lt;/td&gt;
&lt;td&gt;6 / 6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fix and verify&lt;/td&gt;
&lt;td&gt;6 / 6&lt;/td&gt;
&lt;td&gt;6 / 6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;6 / 6&lt;/td&gt;
&lt;td&gt;6 / 6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every run reproduced or verified in the running app, named the right cause, and the fixes type-checked. In two runs the agent went beyond the report: one Argent run noticed the recycled-row bug while fixing the layout bug, and one agent-device run fixed the slow keyword check as well as the state problem, after checking that the new version gives identical results on all 48 questions.&lt;/p&gt;

&lt;p&gt;So on tasks like these, either tool is enough. The model does the reasoning; the tool decides how expensive it is to see the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where they differed: context and cost
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Median per run&lt;/th&gt;
&lt;th&gt;Argent&lt;/th&gt;
&lt;th&gt;agent-device&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Time&lt;/td&gt;
&lt;td&gt;138 s&lt;/td&gt;
&lt;td&gt;108 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tool calls&lt;/td&gt;
&lt;td&gt;34&lt;/td&gt;
&lt;td&gt;16.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Screenshots in the conversation&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Text returned by tools&lt;/td&gt;
&lt;td&gt;59 KB&lt;/td&gt;
&lt;td&gt;17 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tokens processed&lt;/td&gt;
&lt;td&gt;1.84 M&lt;/td&gt;
&lt;td&gt;0.34 M&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost per run (average)&lt;/td&gt;
&lt;td&gt;$1.27&lt;/td&gt;
&lt;td&gt;$0.41&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The difference comes from what each tool sends back. Every Argent interaction (tap, swipe, launch) returns a screenshot and the full accessibility tree, so the agent always sees the screen, and every image stays in the conversation. agent-device's commands return a compact text snapshot or a diff, with short references like &lt;code&gt;@e8&lt;/code&gt; to tap, and screenshots only when the agent asks for one. Over a session, that's the difference between about 1.8 million and 0.3 million tokens.&lt;/p&gt;

&lt;p&gt;The text-first approach had one concrete advantage in this app. agent-device's snapshot printed the pill's selected state as text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@e29 [button] "yes for Entrance mats clean" [selected]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Argent's tree didn't include the selected state, so Argent's agent found the stray "yes" by looking at screenshots. One of its reports says so directly. Both got there; one needed the image.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where they differed: profiling setup
&lt;/h2&gt;

&lt;p&gt;Both tools can profile React renders, and both agents found and measured the slow typing:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Performance runs&lt;/th&gt;
&lt;th&gt;Argent&lt;/th&gt;
&lt;th&gt;agent-device&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Before the fix&lt;/td&gt;
&lt;td&gt;155–179 ms per slow commit, 162 row re-renders&lt;/td&gt;
&lt;td&gt;145–153 ms average per keystroke, every visible row re-rendered&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After the fix&lt;/td&gt;
&lt;td&gt;no commit over 16 ms&lt;/td&gt;
&lt;td&gt;about 1 ms per keystroke&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time per run&lt;/td&gt;
&lt;td&gt;195 s, 229 s&lt;/td&gt;
&lt;td&gt;296 s, 517 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Argent's profiler worked straight away on React Native 0.87. It also sampled the CPU, which pointed straight at the slow code: &lt;code&gt;RegExp&lt;/code&gt; construction took 943 ms of the 1.6 seconds of JavaScript work while typing.&lt;/p&gt;

&lt;p&gt;agent-device's React DevTools needed setup first. On 0.87 both agent-device runs had to install &lt;code&gt;agent-react-devtools&lt;/code&gt; into the project and run its &lt;code&gt;init&lt;/code&gt;, which patches &lt;code&gt;index.js&lt;/code&gt; and &lt;code&gt;metro.config.js&lt;/code&gt;. Both agents undid it afterwards, but it made these its slowest runs. In one, a &lt;code&gt;react-devtools wait --connected&lt;/code&gt; call hung and the agent had to restart the helper. Even so, agent-device's performance runs cost less: $0.80 each against $2.00.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: Check what a profiling setup leaves behind.&lt;/strong&gt; One agent installed the DevTools package with &lt;code&gt;--save-dev&lt;/code&gt;, so it went into &lt;code&gt;package.json&lt;/code&gt; until the agent removed it again. If you let an agent set up profiling in your real repo, review the diff for &lt;code&gt;index.js&lt;/code&gt;, &lt;code&gt;metro.config.js&lt;/code&gt; and &lt;code&gt;package.json&lt;/code&gt; changes before you commit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Different habits
&lt;/h2&gt;

&lt;p&gt;One pattern held in all four fix-and-verify runs. Both Argent runs looked at the broken screen first, then changed the code and checked again. Both agent-device runs changed the code straight from reading it, then checked the app. The rubric didn't require seeing the bug first, and all four fixes were correct. But on a less obvious bug, fixing what the code suggests rather than what the app shows could miss.&lt;/p&gt;

&lt;p&gt;I can't tell from four runs whether this comes from the tools. agent-device's guidance tells the agent to "start immediately", and every Argent action shows the screen, which may encourage looking first.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers don't show
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One model, one app, two runs per task.&lt;/strong&gt; I planned three runs; after two rounds every run had full marks, so I stopped. These tasks didn't separate the tools on success; harder tasks might.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One run was cut off.&lt;/strong&gt; The account running the sessions hit its usage limit during Argent's second performance run. I re-ran it once the limit reset. The cut-off attempt is in the repo, excluded from the totals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The simulator, not a phone.&lt;/strong&gt; Both tools also drive Android and physical devices; I tested neither.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I scored them with Claude.&lt;/strong&gt; The rubric was committed first, the points need evidence from tool output rather than the agent's own claims, and every transcript is public so you can check.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Which should you use?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use agent-device when you run agents on the app a lot&lt;/strong&gt;: many UI checks, CI, or long sessions. It was about three times cheaper per run and quicker on the everyday tasks, and its text snapshots carry states like &lt;code&gt;[selected]&lt;/code&gt; that you'd otherwise need a screenshot for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Argent when profiling is the main job&lt;/strong&gt;, or you want the agent to see the screen by default. Its React and CPU profiler worked on React Native 0.87 with no project changes, and it pointed straight at the slow code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Either way, help the tool.&lt;/strong&gt; Both rely on the accessibility tree. The planted app had &lt;code&gt;accessibilityLabel&lt;/code&gt; and &lt;code&gt;accessibilityState&lt;/code&gt; on its buttons, and that's what let both agents find the right row and read its state. If your app doesn't, the agent falls back to screenshots and coordinates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Both Argent and agent-device let Claude Code reproduce, fix, verify and profile real React Native bugs: 12 of 12 runs got full marks.&lt;/li&gt;
&lt;li&gt;agent-device used about a fifth of the tokens and a third of the cost, because it returns text snapshots instead of a screenshot after every action.&lt;/li&gt;
&lt;li&gt;Argent's React and CPU profiler worked on React Native 0.87 with no setup; agent-device's needed agent-react-devtools installed and two files patched.&lt;/li&gt;
&lt;li&gt;Review the diff after an agent sets up profiling: index.js, metro.config.js and package.json can change.&lt;/li&gt;
&lt;li&gt;Add accessibilityLabel and accessibilityState to interactive elements; both tools read the accessibility tree first.&lt;/li&gt;
&lt;li&gt;To compare agent tools fairly, isolate each session: --setting-sources project doesn't stop global CLAUDE.md and rules loading.&lt;/li&gt;
&lt;li&gt;Keep git history out of the agent's workspace if your commits describe the bugs you're testing.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about React Native in practice, measured and with public code, at &lt;a href="https://www.praveensingh.co.in/blog" rel="noopener noreferrer"&gt;praveensingh.co.in/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>ai</category>
      <category>testing</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
