@@ -25,6 +25,16 @@ export interface KernelOptions {
2525 skipSystemValidation ?: boolean ;
2626 /** MSWPlugin options; when provided, MSWPlugin is added to the kernel. */
2727 mswOptions ?: MSWPluginOptions ;
28+ /**
29+ * InMemoryDriver persistence configuration.
30+ *
31+ * - `'auto'` (default) — auto-detect environment (browser → localStorage, Node.js → file)
32+ * - `'local'` — force localStorage persistence (browser only)
33+ * - `false` — disable persistence entirely (useful in tests)
34+ *
35+ * When omitted, defaults to `'auto'`.
36+ */
37+ persistence ?: false | 'auto' | 'local' | 'file' ;
2838}
2939
3040export interface KernelResult {
@@ -154,9 +164,11 @@ function patchDriverCreate(driver: InMemoryDriver): void {
154164 * so that kernel setup logic is not duplicated.
155165 */
156166export async function createKernel ( options : KernelOptions ) : Promise < KernelResult > {
157- const { appConfig, skipSystemValidation = true , mswOptions } = options ;
167+ const { appConfig, skipSystemValidation = true , mswOptions, persistence } = options ;
158168
159- const driver = new InMemoryDriver ( ) ;
169+ const driver = new InMemoryDriver (
170+ persistence !== undefined ? { persistence } : undefined ,
171+ ) ;
160172
161173 const kernel = new ObjectKernel ( {
162174 skipSystemValidation
@@ -190,5 +202,16 @@ export async function createKernel(options: KernelOptions): Promise<KernelResult
190202 await installBrokerShim ( kernel ) ;
191203 }
192204
205+ // Initialise persistence adapter and load any previously persisted data.
206+ // On first load this is a no-op (empty localStorage); on subsequent page
207+ // refreshes the persisted data overwrites the seed data so that user
208+ // changes survive a browser reload.
209+ await driver . connect ( ) ;
210+
211+ // Ensure the current database state (seed data on first load, or the
212+ // just-restored persisted snapshot) is flushed to the persistence layer
213+ // so that localStorage always contains the latest data.
214+ await driver . flush ( ) ;
215+
193216 return { kernel, driver, mswPlugin } ;
194217}
0 commit comments