Skip to content
PBIXRay
Go back

Share Links That Show the Model: Link Unfurling on PBIX.info

A PBIX.info share link used to arrive in chat as a bare URL, or with the same generic homepage card for every model. Now a link like pbix.info/share/gRBJ1JK6RV unfurls into a picture of the model itself: the file name, the table and relationship counts, and a miniature of the relationship diagram.

A PBIX.info share link unfurled in chat, showing the Adventure Works model diagram

The Adventure Works DW 2020 share, unfurled: nine tables, eleven relationships, the diagram drawn from the stored layout.

This post covers how that works. There are three parts: tags in the HTML, an image rendered on demand, and enough caching to make the image cheap.

How Unfurling Works

When you paste a URL into Slack, Teams, Discord, LinkedIn or X, the platform’s crawler fetches the page and reads <meta> tags from the <head>: Open Graph (og:title, og:description, og:image) and the older twitter:* set. The card you see is built entirely from those tags.

The catch is that crawlers do not run JavaScript. PBIX.info is a single-page React app: every route is served the same index.html, and the share is fetched and rendered client-side. A crawler visiting /share/gRBJ1JK6RV sees the homepage’s tags, so every share link unfurled identically.

So the tags have to be correct in the HTML the server sends.

Rewriting the Shell at the Edge

PBIX.info runs on Cloudflare Pages, and shares live in a D1 (SQLite) table. A Pages Function at functions/share/[id].ts now takes over /share/:id:

  1. fetch the static index.html from the asset store
  2. look up the share in D1
  3. stream the HTML through HTMLRewriter, replacing the title, description, og:* and twitter:* tags

The browser still gets the same SPA shell and boots normally. Only the <head> changes.

The description needs counts of tables, relationships and measures. Those live inside large JSON blobs (the serialized diagram and the extracted DAX/M code), and there is no reason to pull megabytes into the worker just to count array elements. SQLite can count them where they are stored:

SELECT file_name,
       json_array_length(flow_diagram_data, '$.nodes') AS tables,
       json_array_length(flow_diagram_data, '$.edges') AS relationships,
       json_array_length(m_dax_code, '$.daxExpressions') AS measures
FROM shared_diagrams
WHERE unique_id = ?

Only four small values leave D1. If an old row has malformed JSON, the query falls back to the file name alone, and the page is always served even if D1 is unavailable.

The rewrite also adds og:image:width/height/alt, and up to two twitter:label/twitter:data pairs that Slack shows as small “Tables” and “Measures” fields under the description.

Open Graph preview of a PBIX.info share URL across platforms

The rewritten tags, as an Open Graph previewer sees them.

Drawing the Diagram Without a Browser

Text-only cards are fine, but the useful part of a share is the diagram. A second function, functions/share/[id]/og.png.ts, renders a 1200×630 PNG for each share.

There is no headless browser at the edge, and React Flow is not going to run there. The card is built the low-tech way: a function that turns the stored React Flow JSON into an SVG string, and resvg compiled to WebAssembly (@resvg/resvg-wasm) to turn that SVG into a PNG.

The SVG is a simplified redraw of what the app shows, not a screenshot:

Text needs real fonts: resvg has no system fonts at the edge. The card uses JetBrains Mono, subset into Latin, Latin Extended and Cyrillic TTFs and served as static assets. One gotcha: resvg picks the first loaded face that matches family and weight, so the Latin subset has to be loaded first. Otherwise bold headers silently fall back to regular.

Making It Cheap

A render costs roughly 25–45ms of CPU. That is over the 10ms limit of Cloudflare’s free Workers plan, and more than anyone wants to spend each time a crawler visits.

Shares are immutable snapshots, so the image for a share never changes. The PNG is served with Cache-Control: public, max-age=31536000, immutable and stored in the Cloudflare cache on first render. Each share is rendered once per data centre. After that, crawlers get a cached file.

The one thing that can change is the card design. The share page links the image as /share/:id/og.png?v=2; bumping the version gives every share a new URL, which sidesteps both the edge cache and the platforms’ own caches. That matters because Slack, LinkedIn and X all cache unfurls aggressively and give you few ways to clear them.

If rendering fails, the endpoint returns the generic site image with a short cache lifetime, so a crawler still gets a picture.

A few small details:

Limits

The card is an approximation. Edges can pass behind tables the real diagram would route around, CJK table names don’t have glyphs yet, and a model with hundreds of tables becomes a texture rather than a diagram. For the models people actually share in a chat thread, it is enough to answer “what is this?” before anyone clicks.

Try it: share a model from pbix.info and paste the link anywhere.


Share this post on:

Next Post
Windows Already Ships the Decompressor Power Pivot Needs