dorfteich/apps/web/vite.config.ts
Claude Opus 4.8 af81b50fa6
Some checks failed
CD / Build and push images (push) Successful in 2m59s
CI / Lint, typecheck, test (push) Successful in 2m3s
CI / Auth e2e pack (push) Failing after 2m18s
CI / Build container images (push) Has been skipped
CD / Deploy to Test (push) Successful in 9s
CD / Smoke tests against Test (push) Successful in 1m32s
CD / Promote to Int (push) Successful in 12s
Add offline editing: local persistence, PWA shell, offline resolution (#38)
Editing continues without a connection and merges conflict-free on
reconnect (ADR 0003, realtime-collaboration.md §Offline).

- y-indexeddb mirrors every opened page's Y.Doc to IndexedDB, sharing the
  document with the collab provider. The local copy is discarded when the
  page is left after a successful server sync (bounding IndexedDB growth)
  and kept otherwise so offline edits survive to the next visit.
- vite-plugin-pwa service worker precaches the app shell (build assets only)
  with a navigation fallback; `/api` and `/collab` are denylisted and there
  is no runtime caching, so API responses are never cached or poisoned.
- Offline page resolution WITHOUT caching API responses: the app itself
  persists the small metadata it needs to reopen a visited page (page/pond
  ids + slugs, bounded LRU in localStorage) and the last signed-in user, so
  after an offline tab reload the app stays signed in, resolves the page, and
  restores its content from IndexedDB. Both are revalidated when the network
  returns (a 401 clears the cached user).
- Local-only UI: a banner when there are edits held only on this device
  (provider `onUnsyncedChanges`), de + en.

Tests: `page-cache` unit test (remember/recall + bounded eviction); a new
`offline` e2e pack (validated locally against the full stack and wired into
CI): edit, reload while offline (shell from the SW, content from IndexedDB),
assert an API call fails offline (no SW API caching), then reconnect and a
second client converges. The e2e static server serves `.webmanifest`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PGdhRiwU1WRL4XxJfZYipY
2026-07-08 22:08:55 +02:00

47 lines
1.7 KiB
TypeScript

import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
export default defineConfig({
plugins: [
react(),
// PWA app-shell caching for offline editing (issue #38). Only build assets
// are precached; the service worker never caches `/api` or `/collab`
// (no runtime caching + navigation-fallback denylist), so API responses are
// always fresh from the network and never poisoned by a stale cache.
VitePWA({
registerType: 'autoUpdate',
injectRegister: 'auto',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'],
navigateFallback: '/index.html',
navigateFallbackDenylist: [/^\/api/, /^\/collab/],
},
// No dev service worker — the SW is exercised against the production
// build (dist) only, which keeps native `vite` dev free of SW caching.
devOptions: { enabled: false },
manifest: {
name: 'Dorfteich',
short_name: 'Dorfteich',
description: 'Collaborative wiki',
theme_color: '#2f6f4f',
background_color: '#ffffff',
display: 'standalone',
start_url: '/',
},
}),
],
server: {
// Native dev: api on localhost:3001 (3000 may be occupied by other
// projects). Containerized dev overrides this via VITE_API_PROXY_TARGET.
proxy: {
'/api': process.env.VITE_API_PROXY_TARGET ?? 'http://localhost:3001',
// The collab WebSocket (issue #36); `ws: true` upgrades the connection.
'/collab': {
target: process.env.VITE_COLLAB_PROXY_TARGET ?? 'http://localhost:3002',
ws: true,
},
},
},
});