Skip to content

Commit 22e01d0

Browse files
committed
Update browser.ts
1 parent 8f6d6fa commit 22e01d0

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

examples/msw-react-crud/src/mocks/browser.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ export async function startMockServer() {
4242
}));
4343

4444
await kernel.bootstrap();
45+
46+
// Initialize default data from manifest if available
47+
const manifest = (todoConfig as any).manifest;
48+
if (manifest && Array.isArray(manifest.data)) {
49+
console.log('[MSW] Loading initial data...');
50+
for (const dataset of manifest.data) {
51+
if (dataset.object && Array.isArray(dataset.records)) {
52+
for (const record of dataset.records) {
53+
// Check if record already exists to avoid duplicates on hot reload?
54+
// Since it's in-memory and we create new kernel/driver on refresh...
55+
// But 'kernel' variable is module-scoped singleton.
56+
// On HMR replacement, this module might re-execute.
57+
// If 'kernel' is not null, we return early (line 18).
58+
// So data loading happens only once per session. Good.
59+
await driver.create(dataset.object, record);
60+
}
61+
console.log(`[MSW] Loaded ${dataset.records.length} records for ${dataset.object}`);
62+
}
63+
}
64+
}
4565

4666
return kernel;
4767
}

0 commit comments

Comments
 (0)