<?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: Melissa Ashford</title>
    <description>The latest articles on DEV Community by Melissa Ashford (@melissa_lomray).</description>
    <link>https://dev.to/melissa_lomray</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%2F4134517%2F5f0ff78c-36bc-4c3b-a3cc-d46e98c826d3.png</url>
      <title>DEV Community: Melissa Ashford</title>
      <link>https://dev.to/melissa_lomray</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/melissa_lomray"/>
    <language>en</language>
    <item>
      <title>react-mobx-manager 4.6.0: persisting MobX stores without rewriting all of them</title>
      <dc:creator>Melissa Ashford</dc:creator>
      <pubDate>Thu, 05 Nov 2026 21:50:25 +0000</pubDate>
      <link>https://dev.to/lomray-software/react-mobx-manager-460-persisting-mobx-stores-without-rewriting-all-of-them-2fb7</link>
      <guid>https://dev.to/lomray-software/react-mobx-manager-460-persisting-mobx-stores-without-rewriting-all-of-them-2fb7</guid>
      <description>&lt;p&gt;Persistence in react-mobx-manager used to be simple and a bit wasteful. Every persisted store had a MobX reaction on &lt;code&gt;toJS(store)&lt;/code&gt;, and &lt;code&gt;toJS&lt;/code&gt; walks every observable the store can reach, including other stores referenced from its fields. So a loading flag flipping in one store could make another store serialize itself again. Then every save wrote the whole storage value: one JSON blob holding all persisted stores.&lt;/p&gt;

&lt;p&gt;Version 4.6.0 (released 30 September, PR #53, promoted to latest in #54) reworks this. Short version: it saves less, and less often.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the listener watches now
&lt;/h2&gt;

&lt;p&gt;The change listener tracks only the fields that are actually persisted. That is the union of the &lt;code&gt;attributes&lt;/code&gt; you route to storages, or all exported fields when you use &lt;code&gt;'*'&lt;/code&gt;. Stores referenced from those fields are no longer traversed.&lt;/p&gt;

&lt;p&gt;So if a persisted store also has short-lived fields, keep them out of storage. They stop causing persist work:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Manager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;makeExported&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;@lomray/react-mobx-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Manager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;persistStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;FeedStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;feed&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;behaviour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;include&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;local&lt;/span&gt;&lt;span class="p"&gt;:&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&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;filters&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;span class="c1"&gt;// or inside the store constructor&lt;/span&gt;
&lt;span class="nf"&gt;makeExported&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;isFetching&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;excluded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Saves are batched
&lt;/h2&gt;

&lt;p&gt;Stores that change within &lt;code&gt;options.persistDelay&lt;/code&gt; (100 ms by default) are serialized once, and each storage gets one write. A store whose persisted state did not change is not written again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7dhw2nlrhcnuke147d3l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7dhw2nlrhcnuke147d3l.png" alt="Diagram of how a change gets saved: before, a reaction on toJS walks referenced stores and rewrites one JSON blob right away; now the listener watches only persisted fields, batches saves for persistDelay and writes once per storage" width="799" height="462"&gt;&lt;/a&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="nx"&gt;manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Manager&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;persistDelay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;300&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;This is a behaviour change. A save can now land up to &lt;code&gt;persistDelay&lt;/code&gt; after the change. Need the old timing? Set &lt;code&gt;persistDelay: 0&lt;/code&gt;. On the server the manager always saves immediately.&lt;/p&gt;

&lt;p&gt;The queue is written right away in four cases. The page is hidden (&lt;code&gt;pagehide&lt;/code&gt;, or &lt;code&gt;visibilitychange&lt;/code&gt; to hidden). A store with queued changes is destroyed. You call &lt;code&gt;manager.destroy()&lt;/code&gt;. Or you call &lt;code&gt;manager.flushPersist()&lt;/code&gt; yourself. React Native has no page events, so flush when the app goes to background:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppState&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;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;AppState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;change&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="nx"&gt;state&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;active&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;void&lt;/span&gt; &lt;span class="nx"&gt;manager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flushPersist&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;flushPersist()&lt;/code&gt; resolves when the writes finish, to &lt;code&gt;false&lt;/code&gt; if something failed or persistence is disabled. In tests that read storage right after a change, await it first.&lt;/p&gt;

&lt;h2&gt;
  
  
  One key per store: KeyValueStorage
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;LocalStorage&lt;/code&gt;, &lt;code&gt;SessionStorage&lt;/code&gt;, &lt;code&gt;CookieStorage&lt;/code&gt; and &lt;code&gt;AsyncStorage&lt;/code&gt; keep all persisted stores in one value, and their data format did not change in 4.6.0. If you have many or large stores, &lt;code&gt;KeyValueStorage&lt;/code&gt; saves each store under its own key and writes only the stores that changed. Values also stay small. The docs point out why that matters on Android: a single AsyncStorage row of around 2 MB may fail to load.&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="nx"&gt;AsyncStorage&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;@react-native-async-storage/async-storage&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Manager&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;@lomray/react-mobx-manager&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;MobxAsyncStorage&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;@lomray/react-mobx-manager/storages/async-storage&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;CombinedStorage&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;@lomray/react-mobx-manager/storages/combined-storage&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;KeyValueStorage&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;@lomray/react-mobx-manager/storages/key-value-storage&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;manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Manager&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CombinedStorage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;local&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyValueStorage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AsyncStorage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="c1"&gt;// stores saved by the previous setup are moved on the first start&lt;/span&gt;
      &lt;span class="na"&gt;migrateFrom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MobxAsyncStorage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AsyncStorage&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;Any backend with &lt;code&gt;getItem&lt;/code&gt;, &lt;code&gt;setItem&lt;/code&gt; and &lt;code&gt;removeItem&lt;/code&gt; works, sync or async. MMKV, for example:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createMMKV&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;react-native-mmkv&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;mmkv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createMMKV&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;storage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyValueStorage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&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;mmkv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;mmkv&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="nx"&gt;key&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="na"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&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;mmkv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&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;Stores land under &lt;code&gt;stores:&amp;lt;storeId&amp;gt;&lt;/code&gt; next to a &lt;code&gt;stores-keys&lt;/code&gt; index. &lt;code&gt;prefix&lt;/code&gt; changes the prefix.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe5xajdgk738yfo3webuw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe5xajdgk738yfo3webuw.png" alt="Diagram comparing one storage value that is rewritten on every change with KeyValueStorage, where only the changed store key is written" width="800" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Migration is conservative
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;migrateFrom&lt;/code&gt; is read only when the new storage has no index yet, which means the first start. The old data stays where it was by default, so rolling back to an older app version still finds it. Pass &lt;code&gt;shouldRemoveMigrated: true&lt;/code&gt; to remove it right after migration. If the migrated stores cannot be saved, the app still starts with the old data, and every store is saved again on the next change.&lt;/p&gt;

&lt;h2&gt;
  
  
  IndexedDB for the web
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;IndexedDBStorage&lt;/code&gt; saves each store as its own record. Writes are asynchronous, and the quota is much larger than the roughly 5 MB localStorage gives you.&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="nx"&gt;CombinedStorage&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;@lomray/react-mobx-manager/storages/combined-storage&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;IndexedDBStorage&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;@lomray/react-mobx-manager/storages/indexed-db-storage&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;LocalStorage&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;@lomray/react-mobx-manager/storages/local-storage&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;storage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CombinedStorage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;local&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IndexedDBStorage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="c1"&gt;// moved on the first start and used when IndexedDB is not available&lt;/span&gt;
    &lt;span class="na"&gt;migrateFrom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LocalStorage&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;State comes back asynchronously in &lt;code&gt;manager.init()&lt;/code&gt;. Wait for it before rendering persisted stores, for example with &lt;code&gt;shouldInit&lt;/code&gt; on &lt;code&gt;StoreManagerProvider&lt;/code&gt;. If IndexedDB cannot be opened, the storage reads and writes &lt;code&gt;migrateFrom&lt;/code&gt; instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Smaller things
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Custom storages can implement an optional &lt;code&gt;saveChanges({ value, changes, toJSON })&lt;/code&gt; to write only what changed. Plain &lt;code&gt;set&lt;/code&gt; still works.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CookieStorage&lt;/code&gt; warns once in the console when the value goes over 4 KB.&lt;/li&gt;
&lt;li&gt;A store that cannot be serialized (a BigInt, say) no longer breaks saving for the others.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Numbers, with a caveat
&lt;/h2&gt;

&lt;p&gt;PR #53 includes a synthetic benchmark: 24 persisted stores, about 750 KB of state, stores referencing other stores, frequent loading-flag changes, an AsyncStorage-like backend, run in Node in client mode.&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;before&lt;/th&gt;
&lt;th&gt;after, single value&lt;/th&gt;
&lt;th&gt;after, KeyValueStorage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CPU spent on persistence&lt;/td&gt;
&lt;td&gt;~3.8 s&lt;/td&gt;
&lt;td&gt;~0.1-0.2 s&lt;/td&gt;
&lt;td&gt;~0.2 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;storage writes&lt;/td&gt;
&lt;td&gt;92&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;71 (small)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bytes written&lt;/td&gt;
&lt;td&gt;47 MB&lt;/td&gt;
&lt;td&gt;7.6 MB&lt;/td&gt;
&lt;td&gt;1.4 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The final persisted state matched the previous version. It is one synthetic setup, and your app will show different numbers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdiotm3likwuimj7z6e9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdiotm3likwuimj7z6e9p.png" alt="Bar charts from the PR benchmark: bytes written, storage writes and CPU time on persistence, before and after the change, with and without KeyValueStorage" width="800" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Release v4.6.0: &lt;a href="https://github.com/Lomray-Software/react-mobx-manager/releases/tag/v4.6.0" rel="noopener noreferrer"&gt;https://github.com/Lomray-Software/react-mobx-manager/releases/tag/v4.6.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PR #53 with the full change list: &lt;a href="https://github.com/Lomray-Software/react-mobx-manager/pull/53" rel="noopener noreferrer"&gt;https://github.com/Lomray-Software/react-mobx-manager/pull/53&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Persistence recipes: &lt;a href="https://lomray-software.github.io/react-mobx-manager/examples/recipes" rel="noopener noreferrer"&gt;https://lomray-software.github.io/react-mobx-manager/examples/recipes&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Manager API: &lt;a href="https://lomray-software.github.io/react-mobx-manager/api/manager" rel="noopener noreferrer"&gt;https://lomray-software.github.io/react-mobx-manager/api/manager&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tests for 4.6.0 pass on MobX 6.16 and 7.0. Install: &lt;code&gt;npm i @lomray/react-mobx-manager @lomray/consistent-suspense&lt;/code&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>mobx</category>
      <category>reactnative</category>
      <category>javascript</category>
    </item>
    <item>
      <title>A request for /.env shouldn't render your React app</title>
      <dc:creator>Melissa Ashford</dc:creator>
      <pubDate>Tue, 22 Sep 2026 01:17:49 +0000</pubDate>
      <link>https://dev.to/lomray-software/a-request-for-env-shouldnt-render-your-react-app-4j0p</link>
      <guid>https://dev.to/lomray-software/a-request-for-env-shouldnt-render-your-react-app-4j0p</guid>
      <description>&lt;p&gt;A request for &lt;code&gt;/.env&lt;/code&gt; doesn't need a React tree. In the latest release, vite-ssr-boost can reject it before your request hook runs.&lt;/p&gt;

&lt;p&gt;The document guard is on by default. The SSR concurrency limit isn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your hook might not run
&lt;/h2&gt;

&lt;p&gt;The default document methods are GET, HEAD and POST. Other methods get 405 with an &lt;code&gt;Allow&lt;/code&gt; header before &lt;code&gt;onRequest&lt;/code&gt;, HTML loading or route loaders. If your hook handles CORS preflights, include OPTIONS in &lt;code&gt;requestGuard.methods&lt;/code&gt; alongside the methods you still need. That array replaces the defaults.&lt;/p&gt;

&lt;p&gt;Allowing a method doesn't bypass the other checks. For allowed methods, oversized targets get 414 and malformed paths get 400. With the default rules, GET requests for &lt;code&gt;/.env&lt;/code&gt; or &lt;code&gt;/random.php&lt;/code&gt; get a plain 404 without rendering. An unmatched &lt;code&gt;/missing.xml&lt;/code&gt; does too; a matched resource route such as &lt;code&gt;/sitemap.xml&lt;/code&gt; can pass.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;requestGuard: false&lt;/code&gt; disables the new guard and its missing-page handling. This is document-handler behavior, not protection for every request reaching your server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose what a missing page does
&lt;/h2&gt;

&lt;p&gt;For an unmatched document such as &lt;code&gt;/missing&lt;/code&gt;, &lt;code&gt;notFound&lt;/code&gt; defaults to &lt;code&gt;render&lt;/code&gt;: the existing router/render path. &lt;code&gt;spa&lt;/code&gt; serves a client shell with 404; detected bots still take the render path under the default bot policy. A custom Response gives you a static 404 without the render pipeline.&lt;/p&gt;

&lt;p&gt;A catch-all route counts as a match. To apply a missing-page mode there, return &lt;code&gt;'notFound'&lt;/code&gt; from &lt;code&gt;requestGuard.decide&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cached&lt;/code&gt; buffers a router 404 and reuses it while the entry is retained. Concurrent misses for the same key share a render. Hits skip &lt;code&gt;onRequest&lt;/code&gt; and the render pipeline, including loaders and admission. Don't depend on those hooks running for every missing page.&lt;/p&gt;

&lt;p&gt;The default key is shared across missing paths, including the first rendered URL and hydration data. Cold renders use GET without the original body, with Cookie and Authorization removed before the request hook. The URL, other headers and application state can still affect the result. Keep private state out of shared HTML; choose keys for public variations such as locale. If the page depends on a session, keep ordinary rendering instead.&lt;/p&gt;

&lt;p&gt;A configured CSP nonce disables this cache and falls back to ordinary rendering. Failed renders and non-404 results aren't retained. Overloads and server failures keep their error status; a request-hook bypass keeps its own response. The default &lt;code&gt;private, no-store&lt;/code&gt; header on 404 documents can be overridden by document header rules. This HTML cache is separate from browser or CDN caching.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limit renders, not every bit of server work
&lt;/h2&gt;

&lt;p&gt;Admission is opt-in and handler-local, not a cluster-wide cap.&lt;/p&gt;

&lt;p&gt;Set a positive safe integer in &lt;code&gt;admission.maxConcurrency&lt;/code&gt;, or a valid &lt;code&gt;SSR_MAX_CONCURRENCY&lt;/code&gt;. The environment value wins and is read at handler/entry creation. No limit is enabled by default.&lt;/p&gt;

&lt;p&gt;A slot is taken after request initialization and the SSR/SPA decision, before route loaders. At capacity the default response is 503 with &lt;code&gt;Retry-After&lt;/code&gt; and &lt;code&gt;private, no-store&lt;/code&gt;. There is no admission queue. The rejected request's loaders don't run, but &lt;code&gt;onRequest&lt;/code&gt; and HTML loading have already happened.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;admission.overload: 'spa'&lt;/code&gt;, requests that reach a full admission controller get a 200 shell for humans and 503 for detected bots. That isn't the missing-page SPA mode, whose shell uses 404. A custom overload Response is sent as 503.&lt;/p&gt;

&lt;p&gt;On normal streamed completion, the slot stays occupied until the final Fetch response stream is consumed, not merely until React produces a shell. This doesn't mean the last byte has reached the browser. Aborts and errors can release it earlier; redirects and bodyless responses have their own release paths. Ordinary SPA shells and cached 404 hits don't occupy a slot.&lt;/p&gt;

&lt;p&gt;Before deploying, test a preflight that must reach your hook. Check that missing URLs don't share private data. For admission, keep one response stream open and send another SSR request at capacity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lomray-software.github.io/vite-ssr-boost/api/request-guard" rel="noopener noreferrer"&gt;Configuration reference&lt;/a&gt;, &lt;a href="https://github.com/Lomray-Software/vite-ssr-boost/blob/db2b419e16bee8dfdc5c31577af1d21ada833cf5/__tests__/core/not-found.ts" rel="noopener noreferrer"&gt;guard and 404 tests&lt;/a&gt;, &lt;a href="https://github.com/Lomray-Software/vite-ssr-boost/blob/db2b419e16bee8dfdc5c31577af1d21ada833cf5/__tests__/core/admission.ts" rel="noopener noreferrer"&gt;admission tests&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>We deleted Vite from our production server</title>
      <dc:creator>Melissa Ashford</dc:creator>
      <pubDate>Mon, 21 Sep 2026 16:59:28 +0000</pubDate>
      <link>https://dev.to/lomray-software/we-deleted-vite-from-our-production-server-4n1l</link>
      <guid>https://dev.to/lomray-software/we-deleted-vite-from-our-production-server-4n1l</guid>
      <description>&lt;p&gt;vite-ssr-boost is an SSR framework built on Vite. Its production server used to start this way: load Vite, resolve vite.config, build the full CLI command tree, then serve the first request. None of that is needed to serve HTML.&lt;/p&gt;

&lt;p&gt;In 8.4.x we cut it out. The numbers below are our own runs on a pinned template, M3 Pro, installed through npm.&lt;/p&gt;

&lt;p&gt;What the production start used to do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;load Vite and evaluate vite.config&lt;/li&gt;
&lt;li&gt;build the whole Commander command tree just to parse the flags of &lt;code&gt;start&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;spin up the source analysis services that only dev mode uses&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What it does now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ssr-boost build&lt;/code&gt; writes a versioned &lt;code&gt;build/server/ssr-boost.json&lt;/code&gt; with the resolved serving settings. Production reads that file and never evaluates the Vite config.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ssr-boost start&lt;/code&gt; parses its flags with Node's own parser. Every other command loads on demand, keyboard shortcuts load only when there is a TTY.&lt;/li&gt;
&lt;li&gt;An import hook watches the serving path. It rejects vite, rolldown, rollup, commander, diff, parse5, semver, json5 and the babel packages, and it also rejects our own dev-only code: the cli commands, the build, manifest and route parsing services, the plugins. That is the part that keeps it honest. The hook catches accidental imports before they reach production.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What it bought:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cold start 354 ms to 249 ms. A plain Express server with renderToPipeableStream is 171 ms on the same machine.&lt;/li&gt;
&lt;li&gt;RSS 142 MiB to 100 MiB. Same plain Express baseline: 69 MiB.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then the per-request path. React's native Web stream on React 19.2+, the production shell cached instead of rebuilt, boundary scanning only while data frames can still arrive, a plain state script for routes without router data, static dispatch by built prefixes so there is no filesystem lookup per HTML request, the header queued at shell readiness, compression flushed before drain.&lt;/p&gt;

&lt;p&gt;One more part, the one I would copy even if you skip everything else. Acceptance measures a plain Express baseline in the same run and fails the build if cold start goes past 2x that baseline. RSS has its own ceiling in the same file. So if a later change drags the start path back toward Vite, CI fails on a number instead of on someone's memory.&lt;/p&gt;

&lt;p&gt;We also keep a public benchmark repo that runs five SSR frameworks weekly in CI and stores the raw json for every cell: &lt;a href="https://github.com/Lomray-Software/ssr-benchmarks" rel="noopener noreferrer"&gt;https://github.com/Lomray-Software/ssr-benchmarks&lt;/a&gt;. Read it yourself, our claims here are about our own before and after, not about anyone else's framework.&lt;/p&gt;

&lt;p&gt;If you run SSR on Vite, go look at what your production process loads before it answers anything. Count the modules, or run start under --cpu-prof.&lt;/p&gt;

&lt;p&gt;We were loading a build tool in production. It cost about 100 ms and 40 MiB per process.&lt;/p&gt;

&lt;p&gt;Code: &lt;a href="https://github.com/Lomray-Software/vite-ssr-boost" rel="noopener noreferrer"&gt;https://github.com/Lomray-Software/vite-ssr-boost&lt;/a&gt;&lt;br&gt;
Docs: &lt;a href="https://lomray-software.github.io/vite-ssr-boost/" rel="noopener noreferrer"&gt;https://lomray-software.github.io/vite-ssr-boost/&lt;/a&gt;&lt;br&gt;
The PRs with the full detail: &lt;a href="https://github.com/Lomray-Software/vite-ssr-boost/pull/53" rel="noopener noreferrer"&gt;https://github.com/Lomray-Software/vite-ssr-boost/pull/53&lt;/a&gt;, &lt;a href="https://github.com/Lomray-Software/vite-ssr-boost/pull/54" rel="noopener noreferrer"&gt;https://github.com/Lomray-Software/vite-ssr-boost/pull/54&lt;/a&gt;, &lt;a href="https://github.com/Lomray-Software/vite-ssr-boost/pull/55" rel="noopener noreferrer"&gt;https://github.com/Lomray-Software/vite-ssr-boost/pull/55&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
