Our app has a design lab: one route that renders every screen, mascot and effect in the product side by side, so we can judge them against each other instead of flipping between the real app and a Figma file. It lives at /play/lab and it is not supposed to exist in production.
The page file is 18 lines:
import type { Metadata } from 'next'
import { notFound } from 'next/navigation'
import { EffectsLab } from '@/components/lab/EffectsLab'
/**
* A local-only playground for the mascot candidates and game effects, so they
* can be judged side by side before any of them goes into the real game.
* It 404s in production builds.
*/
export const metadata: Metadata = {
title: 'Mascot and effects lab',
robots: { index: false, follow: false },
}
export default function LabPage() {
if (process.env.NODE_ENV === 'production') notFound()
return <EffectsLab />
}
Behind it are 6 files and 1,236 lines of preview UI. The thing that makes the lab worth having is that it imports the product rather than copying it: the player shell, the result screen, the end screen, the player settings, the host stage, the lobby stage, the mascots, and eight separate effect components. A preview that drifts from what ships is worse than no preview, so there is no mock version of anything in there. The lab's own code is layout, labels, and a set of controls for jumping to a given moment.
That is the design. Here is what production actually does with it, which is not what I assumed.
It is deployed, prerendered, and cached
$ curl -sI https://pub-trivia.app/play/lab
HTTP/2 404
x-matched-path: /play/lab
x-nextjs-prerender: 1
x-vercel-cache: HIT
content-length: 17042
Read those four headers together. x-matched-path: /play/lab means the route exists in the deployed routing table. x-nextjs-prerender: 1 means the 404 was generated at build time, not per request: the build ran our component, our component called notFound(), and the resulting 404 page was written to disk as a static artifact. x-vercel-cache: HIT means the CDN is now serving that artifact from an edge node in Frankfurt.
So the page whose entire purpose is to not exist in production exists in production, as a prerendered static file, cached globally. The guard works, in the sense that nobody can see the lab. It does not remove anything.
A notFound() 404 is not the same page as a missing URL
For comparison, a URL with no route behind it at all:
$ curl -sI https://pub-trivia.app/play/nope
HTTP/2 404
x-matched-path: /404
content-length: 16803
Both are 404s, 239 bytes apart, and they are different documents. Diffing them, the difference starts at byte 68, in the opening tag:
<!-- /play/lab -->
<html data-dpl-id="..." id="__next_error__"><head>...
<!-- /play/nope -->
<html data-dpl-id="..." lang="en"><head>...
The route that called notFound() is served as Next's error shell. It has id="__next_error__", it has no lang attribute, and when you strip the scripts and tags out of it, this is all the text in the document:
Pub Quiz App for Pubs and Bars | PubTrivia
That is the <title>. There is no body copy at all. The same treatment of the unmatched URL gives you the real page:
404: Page Not Found
The page you're looking for doesn't exist or has been moved.
Go home
So our actual 404 design, the one with the heading and the Go home link, is in the HTML for a URL that was never a route, and is absent from the HTML for a route that decided not to render. Opening /play/lab in a browser confirms what the empty shell is for: after hydration the client renders the 404 UI and sets lang="en". A visitor sees the right page. A crawler that does not execute JavaScript sees a 404 status, two robots meta tags, and an empty document.
The one thing that does make it to production
In that same browser check, the tab reads:
Mascot and effects lab | PubTrivia
The metadata export is evaluated before the component runs, and notFound() cannot retract it. So of everything in that file, the only part that reaches a production user is the one string naming the thing they are not allowed to see. The server HTML carries its robots value too, which is how you get a 404 page with two robots tags that disagree about follow:
| URL | robots meta tags in the server HTML |
|---|---|
/play/lab |
noindex, nofollow and noindex
|
/play/nope |
index, follow and noindex
|
The second row is the funnier one and it is not about the lab at all: our generic 404 page emits index, follow from one place and noindex from another. Crawlers combine multiple robots tags and take the most restrictive value, so the behaviour is correct, by luck rather than by design. Two tags that contradict each other on the same page means nobody wrote the policy down in one place.
Three overlapping guards, one of them load bearing
The lab is kept private by three independent things, and it is worth being clear about which one is actually doing the work:
-
notFound()onNODE_ENV === 'production'. This is the one that matters, and it is enforced at build time. -
robots: { index: false, follow: false }in the page's metadata. Belt and braces, and as shown above it ships to production whether the page does or not. -
Disallow: /playin robots.txt, which covers the whole play namespace because robots.txt matching is a literal prefix match.
Worth noting what is not in that list: the auth gate. /play is a public route by design, since players join a quiz from a phone with no account, so there is no session check anywhere near this URL. If the NODE_ENV check were deleted, the lab would be fully public immediately. One if is the entire boundary.
What we are changing
Not the guard itself, which is honest and legible, but where it lives. Two options:
- Move the check into
proxy.ts, our middleware, so the production response for/play/labis the real 404 page with its heading and its link, rendered server side, instead of an empty error shell that only becomes a 404 page after hydration. - Stop building the route in production at all, so there is no prerendered artifact and no leaked title.
We are doing the first, because it fixes the user-visible part, and keeping the lab in the normal route tree is exactly what stops it rotting. The leaked title stays until the second one lands, and now that it is a published fact it is harder to forget.
Check it yourself
Everything above is observable from outside:
curl -sI https://pub-trivia.app/play/lab | grep -iE 'HTTP|x-matched-path|x-nextjs-prerender|x-vercel-cache'
curl -sI https://pub-trivia.app/play/nope | grep -iE 'HTTP|x-matched-path'
curl -s https://pub-trivia.app/play/lab | head -c 120 # id="__next_error__", no lang
curl -s https://pub-trivia.app/play/nope | head -c 120 # lang="en"
Then open pub-trivia.app/play/lab in a browser and look at the tab while the page tells you it does not exist. The screens the lab previews are the ones running on pub-trivia.app under the headline and described on pub-trivia.app/features/big-screen-display; the real product they belong to starts at pub-trivia.app/signup, which is free and needs no card.
Top comments (0)