Build a sync engine that queues form submissions locally when offline and syncs them in order when connectivity is restored, with conflict detection.
class SubmissionQueue {
enqueue(submission: Submission): Promise<void>
sync(): Promise<SyncResult>
getStatus(): QueueStatus
}
// Submission: { instanceId: string, formId: string, data: Record<string, unknown>, submittedAt: string }
// SyncResult: { synced: number, failed: number, conflicts: ConflictRecord[], errors: string[] }
// QueueStatus: { pending: number, failed: number, lastSyncAt: string | null }
// ConflictRecord: { instanceId: string, resolution: 'last-write-wins', mergeLog: string }
Storage: persist the queue to IndexedDB (use idb library). Queue must survive page reloads.
Sync strategy:
/api/submissionsinstanceId already exists): resolve via last-write-wins (the local version wins), re-POST with X-Conflict-Resolution: overwrite, log the conflict in ConflictRecordfailedlastSyncAtEvent emitter: emit queued, syncing, synced, conflict, failed events so UI can show sync status.
Write unit tests for: queue persistence across simulated page reloads, conflict detection and resolution, partial sync recovery (fails on item 3 of 5, resumes from item 3).