Skip to content

fix(api): prevent Vercel CDN from caching Electric responses#1864

Merged
saddlepaddle merged 1 commit into
mainfrom
saddlepaddle/vercel-electric-no-cache
Feb 27, 2026
Merged

fix(api): prevent Vercel CDN from caching Electric responses#1864
saddlepaddle merged 1 commit into
mainfrom
saddlepaddle/vercel-electric-no-cache

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Feb 26, 2026

Summary

  • Add vercel.json to apps/api that sets CDN-Cache-Control: no-store and Vercel-CDN-Cache-Control: no-store on /api/electric/* routes
  • Prevents Vercel's edge cache from incorrectly caching and serving stale Electric shape data (per Electric's Vercel guidance)
  • Electric Cloud already provides its own CDN/DDN layer for caching

Test plan

  • bun run typecheck --filter=@superset/api passes

Summary by CodeRabbit

  • Chores
    • Added configuration for API response headers on electric API endpoints.

Vercel's edge cache can serve stale shape data for Electric requests
because it doesn't properly handle offset-based cache keying. Disable
Vercel CDN caching on the Electric proxy route per Electric's docs.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f27ef6 and 5263c65.

📒 Files selected for processing (1)
  • apps/api/vercel.json

📝 Walkthrough

Walkthrough

A new Vercel configuration file is added to the API directory that establishes CDN cache control headers. The configuration targets /api/electric/(.*) paths and sets both CDN-Cache-Control and Vercel-CDN-Cache-Control headers to no-store.

Changes

Cohort / File(s) Summary
Vercel Configuration
apps/api/vercel.json
Adds header rules to disable CDN caching for Electric API routes via Vercel configuration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Whiskers twitch with joy so bright,
Headers set to guard the night,
No cache stored in Vercel's Keep,
Electric paths run swift and deep!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Vercel configuration to prevent CDN caching of Electric responses, which directly matches the file addition and its purpose.
Description check ✅ Passed The description includes a clear summary of changes, links relevant guidance, explains the rationale, and documents testing. However, it lacks formal sections like 'Type of Change' and 'Related Issues' from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch saddlepaddle/vercel-electric-no-cache

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 26, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ✅ Electric Fly.io app

Thank you for your contribution! 🎉

@saddlepaddle saddlepaddle merged commit ae64aa4 into main Feb 27, 2026
21 of 22 checks passed
@Kitenite Kitenite deleted the saddlepaddle/vercel-electric-no-cache branch February 27, 2026 09:28
saddlepaddle added a commit that referenced this pull request Mar 3, 2026
* Revert "fix(api): prevent Vercel CDN from caching Electric responses (#1864)"

This reverts commit ae64aa4.

* feat(electric-proxy): add Cloudflare Worker proxy for Electric with JWT auth

Replace the API server's Electric proxy with a standalone Cloudflare Worker
that authenticates via JWT instead of session tokens. This decouples Electric
from the API server and enables edge caching via Cloudflare's Cache API.

The worker supports both local Docker Electric (ELECTRIC_URL + ELECTRIC_SECRET)
and Electric Cloud (ELECTRIC_SOURCE_ID + ELECTRIC_SOURCE_SECRET), matching the
dual-mode pattern from the old API proxy.

Desktop changes:
- Rename electricJwt → jwt, add jwtClient() plugin to auth client
- Fetch JWT from authClient.token() response body during hydration
- Periodic JWT refresh every 50 minutes
- Collections use JWT-only auth headers for the worker

* refactor(electric-proxy): move AuthContext/WhereClause to auth.ts, simplify types.ts to Env only

* feat: point desktop Electric URL to Cloudflare Worker and add CI deploy job

* fix: add local Electric vars to .dev.vars, guard JWT hydration, accept JWTs in old proxy

* feat: add electric-cloud feature flag, simplify proxy routing

- Old Vercel proxy always routes to Fly.io (removed cloud/email check)
- Cloudflare Worker always routes to Electric Cloud (removed dual-mode)
- Desktop uses PostHog `electric-cloud` flag to pick proxy
- Default: old proxy (Fly.io), flag on: Cloudflare Worker (Electric Cloud)

* fix: mock posthog-js/react in CollectionsProvider test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant