env.inspector
06 / 10Danger patternServer Componentsrendered HTMLview-source

"SSR is not an API"

Server-Side Rendering is not an API. An API returns data to a caller that then decides what to do with it. SSR renders a document and sends the whole document to the browser. "It ran on the server" and "the browser never sees it" are two different claims — this page stages the mistake of assuming the first implies the second.

✕Live demo — this page is currently leaking a (fake) secret
The card below renders process.env.STRIPE_SECRET_KEY directly into this Server Component's JSX, in full. It is a real demo value, but this is exactly what a real leak looks like: no client-side code did this, no fetch call did this, no build misconfiguration did this. A Server Component simply printed a server-only variable into the markup it returned, and that markup is the HTML sent to your browser right now.
process.env.STRIPE_SECRET_KEYLeaked
undefined

Rendered in full, on purpose, for this demo only.

page.jsx (the mistake)
export default function Page() {
  // This function runs on the server. That part is true.
  // But its return value is the HTML sent to the browser — the two
  // facts are unrelated to each other.
  return <div>{process.env.STRIPE_SECRET_KEY}</div>
}

The fix: use the secret, render the outcome

The correct pattern still runs entirely on the server — it just never puts the raw value into what gets returned.

process.env.STRIPE_SECRET_KEYMasked
undefined

Same variable, same server, same request. The only difference is what the JSX returns.

page.jsx (the fix)
export default async function Page() {
  const key = process.env.STRIPE_SECRET_KEY || ''
  // Use the key server-side — call an API, query a DB, sign something —
  // then render only what the browser actually needs to see.
  const preview = key.slice(0, 4) + '••••••••' + key.slice(-2)
  return <div>{preview}</div>
}
ℹWhere this misconception usually comes from
Developers coming from a client-only framework (plain React, a SPA calling a separate backend) are used to a hard wall between "my server" and "my UI code." Server Components blur that line on purpose — they let you write server-only logic inline with your UI, which is powerful, but it means the old assumption "this code only runs on my server, so it's safe" is no longer enough by itself. The question that matters now is: what does this component return?
Verify it yourself
  1. 1
    View source on this page right now (Ctrl/Cmd+U) and search for sk_test_DEMO. It's in the raw HTML — no DevTools JS inspection required, because this never touched client-side JavaScript at all.
  2. 2
    Disable JavaScript entirely in DevTools (Command Menu → "Disable JavaScript") and reload. The leaked value is still on the page. That's the clearest possible proof that this has nothing to do with client-side code.
  3. 3
    Compare with the masked card: search the page source for the last four characters of the real key printed above it — you'll find them only inside the first, intentionally-leaky card.
Self-check0/3 answered
  • "This code runs on the server" is enough on its own to guarantee a value stays private.

  • Server-Side Rendering works like calling an API: the server computes something and only the caller who asked for it sees the result.

  • Disabling JavaScript in the browser would hide a secret that was rendered directly into a Server Component’s HTML.