Frameworks
Why X Cards fail on React and other single-page apps
Why link previews break on React, Vue and Angular apps, and four fixes that put card tags in the HTML: SSR, prerendering, edge injection or one shared card.
Short answer
X Cards fail on single-page apps because Twitterbot reads the HTML your server sends and does not run JavaScript, so tags that React, Vue or Angular add in the browser never reach it; render the tags on the server, prerender each route at build time, or inject them at the edge.
Key takeaways
- Twitterbot and most link preview bots read the first HTML response and skip JavaScript.
- Helmet-style libraries that set tags in the browser don't help link previews.
- Server rendering or build-time prerendering puts per-page tags into the HTML.
- If neither is possible, an edge function or a shared site-wide card is the fallback.
Your app looks perfect in the browser. The tab shows the right title, the page has the right image, and you set every meta tag with a head-management library. Then someone shares a link on X and gets a bare URL, or the same generic card for every page. The tags are there when you inspect the page. They just aren't there when Twitterbot asks for it.
Why don't my tags show up for X?
Your tags don't show up because Twitterbot reads only the HTML your server sends, and a single-page app sends an almost empty shell that JavaScript fills in later.
Open View Source on any route of a client-rendered React, Vue or Angular app. You'll see something like this:
<head>
<title>My App</title>
</head>
<body>
<div id="root"></div>
<script src="/assets/index-a1b2c3.js"></script>
</body>
That's what Twitterbot receives. Your router, your data fetching and your <Helmet> or useHead calls all run later, in a browser, which the crawler doesn't have. The developer tools Elements panel shows the DOM after JavaScript, so it looks correct, and that's what misleads people.
The Card Preview & Meta Inspector helps here: paste the HTML from View Source, not from the Elements panel, and it shows what X will actually find.
Why does Google index the page but X shows no card?
Google renders JavaScript before indexing, while link preview bots from X, Facebook, LinkedIn, Slack and Apple Messages generally read the raw HTML only.
Google's JavaScript SEO documentation describes a crawl, render and index pipeline. That rendering step is what lets client-side apps rank. Link preview bots have no such step. They need an answer within seconds, and they read the response as it arrives. So "Google can see it" tells you nothing about cards.
How do I fix it?
Put the card tags into the HTML response, either by rendering on the server, prerendering each route at build time or injecting tags at the edge.
| Approach | How it works | Good for | Cost |
|---|---|---|---|
| Server-side rendering | Each request renders the page, tags included, on the server | Apps with dynamic content per URL | Needs a server or serverless runtime |
| Prerendering at build | Build tool writes an HTML file per route with its tags | Marketing pages, docs, blogs | Rebuild when content changes |
| Edge injection | A function rewrites the head of index.html for each path | Existing SPAs you can't restructure | Extra code at the CDN |
| One static card | Fixed tags in index.html for all URLs | Small apps, quick fix | Every link looks the same |
Server-side rendering
Frameworks built on React, Vue or Svelte with server rendering write tags into the response for each request. If you're starting fresh or migrating anyway, this is the cleanest answer. Next.js, Nuxt, SvelteKit and Astro all produce HTML with tags per route. Our setup notes for Next.js, Astro and Shopify cover the specifics.
Prerendering
If your pages are known in advance, many build tools can render each route to static HTML. Product pages, blog posts and documentation fit well. Each file contains its own twitter: and og: tags. The app still hydrates and behaves as a SPA once loaded.
Edge injection
For an existing SPA you can't restructure, an edge function on your CDN can intercept requests, look up the title, description and image for the path and insert them into the head of index.html before it's sent. The rest of the app stays unchanged. Keep the lookup fast and cache it.
Google describes serving different content to bots, called dynamic rendering, as a workaround it no longer recommends for search. Edge injection avoids that problem by giving every visitor, human or bot, the same HTML with the right tags.
One static card
The fastest fix is to add fixed tags to index.html:
<meta name="twitter:card" content="summary_large_image">
<meta property="og:title" content="My App: what it does in a few words">
<meta property="og:description" content="One sentence about the app.">
<meta property="og:image" content="https://example.com/og/default.png">
Every shared link then shows the same card. It's a reasonable stopgap while you plan one of the other fixes. The Card Meta Tag Generator writes this block for you.
How do I check that it works?
Fetch the page the way a bot would, with curl or View Source, and confirm the card tags are in the response for each route you care about.
- Run
curl -s https://example.com/products/blue-mug/ | grep -i 'twitter:\|og:'. - Confirm the title and image are specific to that route, not the homepage defaults.
- Check the image URL is absolute and returns a 200.
- Paste the URL into the X composer with a fresh query string to see a new preview.
If curl shows the right tags but X still shows an old card, it's the cache. Our guide to why an X card isn't showing walks through the rest of the checklist.
What can still go wrong after the fix?
After the fix, duplicate tags, relative image paths, bot protection and hash-based URLs are the usual reasons a card still misbehaves.
- Duplicate tags. Server-rendered tags plus a client library adding its own copy can leave two
og:imagetags. Crawlers usually take the first. - Relative image paths.
/og/mug.pngworks in the browser and fails for crawlers. Use fullhttps://URLs. - Bot protection. A JavaScript challenge in front of the app blocks Twitterbot even when the HTML is perfect.
- Hash routing. URLs like
/#/products/mugsend the same request for every page, because the part after#never reaches the server. Switch to path-based routing for anything you want shared.
Questions
Does Twitterbot run JavaScript?
No. Twitterbot fetches the page and reads the meta tags in the HTML response. Tags that a script adds after the page loads are not part of that response, so the crawler never sees them.
Will react-helmet fix my X Cards?
Not on its own. Libraries like react-helmet change the document head in the browser, which helps the tab title but not crawlers. They only help link previews when used with server-side rendering, where the tags are written into the HTML before it is sent.
Is Google different?
Yes. Google Search renders JavaScript for indexing, so a single-page app can rank while its link previews on X stay blank. Link preview bots from X, Facebook, LinkedIn, Slack and Apple Messages generally read only the HTML.
Can I use one card for every page?
Yes. Static tags in index.html give every URL the same card. It is better than no card and takes a minute, but every shared link will show the same title and image.