All articles

Architecture

Dynamic OG Tags for React SPA: Cloudflare Workers + Supabase Edge Functions

How to fix the generic Open Graph preview problem in React SPAs — using Cloudflare Workers to intercept crawler requests and serve dynamic meta tags from Supabase in real time.

Published
Reading time
12 min read
Written by
Rakesh · DEVMANUSH RAKY
Dynamic OG Tags for React SPA: Cloudflare Workers + Supabase Edge Functions

Single Page Applications (SPAs) offer incredible user experiences but often fail when it comes to social sharing. When a user shares a dynamic path—like a specific player profile or team roster—crawlers from LinkedIn, Slack, or Discord only see the generic index.html. Here is how we implemented a robust, edge-side solution to fix this permanently.

The Challenge: Static HTML in a Dynamic World

In an SPA, the server returns the same basic HTML file for every route. React or Vue then takes over in the browser to render the specific content. However, SEO crawlers are simple: they fetch the HTML and parse meta tags immediately without executing JavaScript. This results in every shared link showing the same generic 'Home Page' preview, which hurts engagement and brand discovery.

The Architecture: Intercepting the Crawler

Our solution used a two-tier approach to identify and serve the correct metadata without slow full-page SSR (Server Side Rendering):

Debugging the Routing: Lovable Infrastructure Conflicts

During implementation, we hit a major roadblock. The site was hosted on Lovable, and adding a custom domain inside their dashboard created its own routing that bypassed our Cloudflare Workers entirely. Even though our DNS pointed to Cloudflare, the traffic was being swallowed by the hosting provider's internal routing before our Worker could run.

The Final Fix: Worker Custom Domains

To solve this, we moved to a 'Worker Custom Domain' architecture. By removing the domain from the hosting platform's dashboard and attaching it directly to the Cloudflare Worker, we ensured we had 100% control over the request lifecycle.

Verification and Results

Using the LinkedIn Post Inspector, we verified that sharing a specific team link now correctly displays the team's custom name, player count, and generated roster image. Performance remained blazing fast because we only serve a few hundred bytes of HTML to crawlers, while humans still get the full React experience.

  • SEO
  • Cloudflare Workers
  • React
  • Supabase
  • Open Graph
  • SPAs
Share

Keep reading