From fa6b8743131123e28b0b4d9854795960194bf928 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Mon, 10 Nov 2025 14:36:30 -0800 Subject: [PATCH] fix typescript errors --- DEPLOYMENT_SUMMARY.md | 103 ++++++++++++++++++++++++++++++ src/automerge/useAutomergeSync.ts | 26 ++++---- 2 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 DEPLOYMENT_SUMMARY.md diff --git a/DEPLOYMENT_SUMMARY.md b/DEPLOYMENT_SUMMARY.md new file mode 100644 index 0000000..7cc0f6c --- /dev/null +++ b/DEPLOYMENT_SUMMARY.md @@ -0,0 +1,103 @@ +# Deployment Summary + +## Current Setup + +### ✅ Frontend: Cloudflare Pages +- **Deployment**: Automatic on push to `main` branch +- **Build**: `npm run build` +- **Output**: `dist/` +- **Configuration**: Set in Cloudflare Pages dashboard +- **Environment Variables**: Set in Cloudflare Pages dashboard (VITE_* variables) + +### ✅ Worker: GitHub Actions +- **Production**: Deploys on push to `main` branch → uses `wrangler.toml` +- **Dev**: Deploys on push to `automerge/**` branches → uses `wrangler.dev.toml` +- **Manual**: Can trigger via GitHub Actions UI with environment selection + +### ❌ Vercel: Can be disabled +- Frontend is now on Cloudflare Pages +- Worker was never on Vercel +- You can safely disconnect/delete the Vercel project + +## Why GitHub Actions for Workers? + +**GitHub Actions is better than Cloudflare's automatic worker deployments because:** + +1. ✅ **More Control**: You can add tests, checks, conditional logic +2. ✅ **Better Branching**: Different configs for dev vs prod +3. ✅ **Manual Triggers**: Deploy specific environments on demand +4. ✅ **No Conflicts**: Single source of truth (no competing deployments) +5. ✅ **Version Tracking**: All deployments tracked in GitHub +6. ✅ **Flexibility**: Can add deployment gates, notifications, etc. + +**Cloudflare's automatic worker deployments:** +- ❌ Less control over the process +- ❌ Can conflict with GitHub Actions +- ❌ Harder to debug when issues occur +- ❌ Limited branching/environment support + +## Environment Switching + +### For Local Development + +You can switch between dev and prod workers locally using: + +```bash +# Switch to production worker +./switch-worker-env.sh production + +# Switch to dev worker +./switch-worker-env.sh dev + +# Switch to local worker (requires local worker running) +./switch-worker-env.sh local +``` + +This updates `.env.local` with `VITE_WORKER_ENV=production` or `VITE_WORKER_ENV=dev`. + +**Default**: Now set to `production` (changed from `dev`) + +### For Cloudflare Pages + +Set environment variables in Cloudflare Pages dashboard: +- **Production**: `VITE_WORKER_ENV=production` +- **Preview**: `VITE_WORKER_ENV=dev` (for testing) + +## Deployment Workflow + +### Frontend (Cloudflare Pages) +1. Push to `main` → Auto-deploys to production +2. Create PR → Auto-deploys to preview environment +3. Environment variables set in Cloudflare dashboard + +### Worker (GitHub Actions) +1. **Production**: Push to `main` → Auto-deploys to production worker +2. **Dev**: Push to `automerge/**` branch → Auto-deploys to dev worker +3. **Manual**: Go to Actions → "Deploy Worker" → Run workflow → Choose environment + +## Testing Both Environments + +### Local Testing +```bash +# Test with production worker +./switch-worker-env.sh production +npm run dev + +# Test with dev worker +./switch-worker-env.sh dev +npm run dev +``` + +### Remote Testing +- **Production**: Visit your production Cloudflare Pages URL +- **Dev**: Visit your dev worker URL directly or use preview deployment + +## Next Steps + +1. ✅ **Disable Vercel**: Go to Vercel dashboard → Disconnect repository +2. ✅ **Verify Cloudflare Pages**: Ensure it's deploying correctly +3. ✅ **Test Worker Deployments**: Push to main and verify production worker updates +4. ✅ **Test Dev Worker**: Push to `automerge/test` branch and verify dev worker updates + + + diff --git a/src/automerge/useAutomergeSync.ts b/src/automerge/useAutomergeSync.ts index 4ea90b2..ab49efe 100644 --- a/src/automerge/useAutomergeSync.ts +++ b/src/automerge/useAutomergeSync.ts @@ -119,27 +119,29 @@ export function useAutomergeSync(config: AutomergeSyncConfig): TLStoreWithStatus try { // Create a deep copy to ensure Automerge properly handles nested objects // This is critical for preserving nested structures like props, richText, etc. + // Cast record to any to access properties that may not exist on all TLRecord types + const recordAny = record as any let recordToSave: any try { recordToSave = JSON.parse(JSON.stringify(record)) // Verify essential properties are preserved - if (!recordToSave.typeName && record.typeName) { - recordToSave.typeName = record.typeName + if (!recordToSave.typeName && recordAny.typeName) { + recordToSave.typeName = recordAny.typeName } - if (!recordToSave.id && record.id) { - recordToSave.id = record.id + if (!recordToSave.id && recordAny.id) { + recordToSave.id = recordAny.id } - if (!recordToSave.type && record.type) { - recordToSave.type = record.type + if (!recordToSave.type && recordAny.type) { + recordToSave.type = recordAny.type } - if (!recordToSave.props && record.props) { - recordToSave.props = record.props + if (!recordToSave.props && recordAny.props) { + recordToSave.props = recordAny.props } // Copy all enumerable properties that might have been lost - for (const prop in record) { + for (const prop in recordAny) { if (!(prop in recordToSave)) { try { - recordToSave[prop] = record[prop] + recordToSave[prop] = recordAny[prop] } catch (e) { // Skip properties that can't be accessed } @@ -149,9 +151,9 @@ export function useAutomergeSync(config: AutomergeSyncConfig): TLStoreWithStatus // If JSON serialization fails, manually copy properties console.warn(`⚠️ JSON serialization failed for record ${key}, using manual copy`) recordToSave = {} - for (const prop in record) { + for (const prop in recordAny) { try { - recordToSave[prop] = record[prop] + recordToSave[prop] = recordAny[prop] } catch (e) { // Skip properties that can't be accessed }