Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

index.tsx

162 lines6.5 KB

1import { Link, createFileRoute } from '@tanstack/react-router'
2​
3export const Route = createFileRoute(`/`)({
4 component: Home,
5})
6​
7function Home() {
8 return (
9 <div className="min-h-screen bg-gray-100">
10 <div className="max-w-4xl mx-auto py-12 px-6">
11 <div className="text-center mb-12">
12 <h1 className="text-4xl font-bold text-gray-900 mb-4">
13 TanStack Offline Transactions Demo
14 </h1>
15 <p className="text-xl text-gray-600 max-w-2xl mx-auto">
16 Experience offline-first development with automatic data
17 persistence, multi-tab coordination, and seamless sync when
18 connectivity returns.
19 </p>
20 </div>
21​
22 <div className="grid md:grid-cols-2 gap-8 mb-12">
23 <Link to="/indexeddb">
24 <div className="bg-white rounded-lg shadow-lg p-6 hover:shadow-xl transition-shadow cursor-pointer group">
25 <div className="flex items-center mb-4">
26 <span className="text-3xl mr-3">🗄️</span>
27 <h2 className="text-2xl font-bold text-gray-900 group-hover:text-blue-600">
28 IndexedDB Storage
29 </h2>
30 </div>
31 <p className="text-gray-600 mb-4">
32 Persistent offline storage with IndexedDB. Best performance and
33 reliability for offline-first applications.
34 </p>
35 <div className="flex flex-wrap gap-2">
36 <span className="px-2 py-1 bg-green-100 text-green-800 text-xs rounded">
37 High Storage Limit
38 </span>
39 <span className="px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded">
40 Structured Data
41 </span>
42 <span className="px-2 py-1 bg-purple-100 text-purple-800 text-xs rounded">
43 Async API
44 </span>
45 </div>
46 </div>
47 </Link>
48​
49 <Link to="/localstorage">
50 <div className="bg-white rounded-lg shadow-lg p-6 hover:shadow-xl transition-shadow cursor-pointer group">
51 <div className="flex items-center mb-4">
52 <span className="text-3xl mr-3">💾</span>
53 <h2 className="text-2xl font-bold text-gray-900 group-hover:text-blue-600">
54 localStorage Fallback
55 </h2>
56 </div>
57 <p className="text-gray-600 mb-4">
58 Reliable fallback storage using localStorage. Works everywhere
59 but with storage limitations.
60 </p>
61 <div className="flex flex-wrap gap-2">
62 <span className="px-2 py-1 bg-yellow-100 text-yellow-800 text-xs rounded">
63 Universal Support
64 </span>
65 <span className="px-2 py-1 bg-orange-100 text-orange-800 text-xs rounded">
66 Sync API
67 </span>
68 <span className="px-2 py-1 bg-red-100 text-red-800 text-xs rounded">
69 Limited Storage
70 </span>
71 </div>
72 </div>
73 </Link>
74 </div>
75​
76 <div className="mb-8">
77 <Link to="/wa-sqlite">
78 <div className="bg-white rounded-lg shadow-lg p-6 hover:shadow-xl transition-shadow cursor-pointer group border-2 border-emerald-200">
79 <div className="flex items-center mb-4">
80 <span className="text-3xl mr-3">🗃️</span>
81 <div>
82 <h2 className="text-2xl font-bold text-gray-900 group-hover:text-emerald-600">
83 wa-sqlite OPFS Persistence
84 </h2>
85 <span className="text-xs px-2 py-0.5 bg-emerald-100 text-emerald-700 rounded-full">
86 NEW
87 </span>
88 </div>
89 </div>
90 <p className="text-gray-600 mb-4">
91 Collection-level persistence using wa-sqlite with OPFS. Data is
92 stored in a real SQLite database in the browser via a Web
93 Worker. Survives page reloads without server sync.
94 </p>
95 <div className="flex flex-wrap gap-2">
96 <span className="px-2 py-1 bg-emerald-100 text-emerald-800 text-xs rounded">
97 SQLite in Browser
98 </span>
99 <span className="px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded">
100 OPFS Storage
101 </span>
102 <span className="px-2 py-1 bg-purple-100 text-purple-800 text-xs rounded">
103 Web Worker
104 </span>
105 <span className="px-2 py-1 bg-orange-100 text-orange-800 text-xs rounded">
106 Local-only
107 </span>
108 </div>
109 </div>
110 </Link>
111 </div>
112​
113 <div className="bg-white rounded-lg shadow-lg p-8">
114 <h2 className="text-2xl font-bold text-gray-900 mb-6">
115 Features Demonstrated
116 </h2>
117 <div className="grid md:grid-cols-2 gap-6">
118 <div>
119 <h3 className="text-lg font-semibold text-gray-800 mb-3">
120 📦 Outbox Pattern
121 </h3>
122 <p className="text-gray-600 text-sm">
123 Mutations are persisted before being applied, ensuring zero data
124 loss during offline periods.
125 </p>
126 </div>
127​
128 <div>
129 <h3 className="text-lg font-semibold text-gray-800 mb-3">
130 🔄 Automatic Retry
131 </h3>
132 <p className="text-gray-600 text-sm">
133 Failed operations are retried with exponential backoff when
134 connectivity is restored.
135 </p>
136 </div>
137​
138 <div>
139 <h3 className="text-lg font-semibold text-gray-800 mb-3">
140 👥 Multi-tab Coordination
141 </h3>
142 <p className="text-gray-600 text-sm">
143 Leader election ensures only one tab manages offline storage,
144 preventing conflicts.
145 </p>
146 </div>
147​
148 <div>
149 <h3 className="text-lg font-semibold text-gray-800 mb-3">
150 ⚡ Optimistic Updates
151 </h3>
152 <p className="text-gray-600 text-sm">
153 UI updates immediately while mutations sync in the background,
154 providing snappy user experience.
155 </p>
156 </div>
157 </div>
158 </div>
159 </div>
160 </div>
161 )