Production rendering depends on request APIs, caching configuration and route behaviour. A simulator can teach the shape of an app without exercising all of those decisions.
Read, predict, run
The model turns what a project uses into the checks it needs on a real server.
A component that reads browser-only values needs a hydration check; one that
reads cookies needs a test with two different callers:
Before pressing Run, predict what run returns for {"usesBrowserApi": true, "usesCookies": false}, from the
code above. Write your answers down first: after Run, the case table shows the
expected values beside the actual ones.
Audit What the Simulator Cannot ShowNext.js · 6 filesimport "./globals.css";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<header>
<strong>Review Queue · Practice lab</strong>
</header>
{children}
</body>
</html>
);
}
import Cases from "./Cases.jsx";
import LastChecked from "./LastChecked.jsx";
export default function Page() {
return (
<main>
<h1>Audit What the Simulator Cannot Show</h1>
<LastChecked />
<p>
lib/contract.js turns what a project uses into the checks it needs on a
real server.
</p>
<Cases />
</main>
);
}
import { run, examples } from "@/lib/contract.js";
const text = (value) => JSON.stringify(value) ?? "undefined";
export default async function Cases() {
const results = await Promise.all(
examples.map(async ([input, expected]) => {
// Record the input before running, to show whether run changed it.
const before = text(input);
const actual = await run(input);
return {
input: before,
expected,
actual,
kept: text(input) === before,
pass: text(actual) === text(expected),
};
}),
);
return (
<section>
<h2>Executable cases</h2>
<p>
Checks: {results.filter((row) => row.pass).length}/{results.length}{" "}
passed
</p>
<table>
<thead>
<tr>
<th>Input</th>
<th>Expected</th>
<th>Actual</th>
<th>Input kept</th>
</tr>
</thead>
<tbody>
{results.map((row, i) => (
<tr key={i}>
<td>
<code>{row.input}</code>
</td>
<td>
<code>{text(row.expected)}</code>
</td>
<td className={row.pass ? "pass" : "fail"}>
<code>{text(row.actual)}</code>
</td>
<td className={row.kept ? "pass" : "fail"}>
{row.kept ? "yes" : "no: run changed it"}
</td>
</tr>
))}
</tbody>
</table>
</section>
);
}
"use client";
import { useEffect, useState } from "react";
// The server and the first browser render both produce "just now"; the
// reader's local time replaces it after hydration.
export default function LastChecked() {
const [time, setTime] = useState(null);
useEffect(() => {
setTime(new Date().toLocaleTimeString());
}, []);
return <p>Queue checked {time ? `at ${time}` : "just now"}</p>;
}
body {
font: 16px/1.5 system-ui;
margin: 0;
color: #182b3c;
background: #f4f8fc;
}
header,
main {
max-width: 900px;
margin: auto;
padding: 20px;
}
header {
border-bottom: 1px solid #cbd5e1;
}
a {
color: #075985;
}
button,
input,
textarea,
select {
font: inherit;
padding: 8px;
margin: 4px;
}
button {
cursor: pointer;
}
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
padding: 10px;
border: 1px solid #cbd5e1;
text-align: left;
vertical-align: top;
}
pre,
code {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.pass {
color: #166534;
}
.fail,
[role="alert"] {
color: #a01818;
}
section {
margin: 16px 0;
padding: 12px;
background: white;
border-radius: 8px;
}
nav {
display: flex;
gap: 16px;
}
export function run({ usesBrowserApi, usesCookies }) {
return {
hydration: Boolean(usesBrowserApi),
requestIsolation: Boolean(usesCookies),
};
}
export const examples = [
[
{ usesBrowserApi: true, usesCookies: false },
{ hydration: true, requestIsolation: false },
],
];
Runs with real Next.js on your computer: unzip, then npm install and npm run dev.
The case table computes these results on the server side of the simulation.
It compares values; it does not prove a production deployment or database works.
A mismatch the simulator can't show
Here's a header line for the Review Queue, written the obvious way:
JSX
"use client";export default function LastChecked() { return <p>Queue checked at {new Date().toLocaleTimeString()}</p>;}
Trace one page load on a real server in London, read from Tokyo:
The server renders the client component to HTML, in its own time zone:
Queue checked at 09:15:02.
The browser shows that HTML at once, then React renders the same component
again to attach event handlers. That render runs in Tokyo, a second later:
Queue checked at 18:15:03.
The two disagree, and next dev reports:
Text
Hydration failed because the server rendered text didn't match the client.
React then discards the server's HTML for that part and builds it again in the
browser. A useEffect that set the right time afterwards wouldn't help: the
mismatch is detected before effects run. The fix is to make the first render
the same on both sides, then change it in an effect:
The lab uses the fixed version, in app/LastChecked.jsx. Run it: you'll see
Queue checked just now briefly, then a time.
The fixed componentNext.js · 6 filesimport "./globals.css";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<header>
<strong>Review Queue · Practice lab</strong>
</header>
{children}
</body>
</html>
);
}
import Cases from "./Cases.jsx";
import LastChecked from "./LastChecked.jsx";
export default function Page() {
return (
<main>
<h1>Audit What the Simulator Cannot Show</h1>
<LastChecked />
<p>
lib/contract.js turns what a project uses into the checks it needs on a
real server.
</p>
<Cases />
</main>
);
}
import { run, examples } from "@/lib/contract.js";
const text = (value) => JSON.stringify(value) ?? "undefined";
export default async function Cases() {
const results = await Promise.all(
examples.map(async ([input, expected]) => {
// Record the input before running, to show whether run changed it.
const before = text(input);
const actual = await run(input);
return {
input: before,
expected,
actual,
kept: text(input) === before,
pass: text(actual) === text(expected),
};
}),
);
return (
<section>
<h2>Executable cases</h2>
<p>
Checks: {results.filter((row) => row.pass).length}/{results.length}{" "}
passed
</p>
<table>
<thead>
<tr>
<th>Input</th>
<th>Expected</th>
<th>Actual</th>
<th>Input kept</th>
</tr>
</thead>
<tbody>
{results.map((row, i) => (
<tr key={i}>
<td>
<code>{row.input}</code>
</td>
<td>
<code>{text(row.expected)}</code>
</td>
<td className={row.pass ? "pass" : "fail"}>
<code>{text(row.actual)}</code>
</td>
<td className={row.kept ? "pass" : "fail"}>
{row.kept ? "yes" : "no: run changed it"}
</td>
</tr>
))}
</tbody>
</table>
</section>
);
}
"use client";
import { useEffect, useState } from "react";
// The server and the first browser render both produce "just now"; the
// reader's local time replaces it after hydration.
export default function LastChecked() {
const [time, setTime] = useState(null);
useEffect(() => {
setTime(new Date().toLocaleTimeString());
}, []);
return <p>Queue checked {time ? `at ${time}` : "just now"}</p>;
}
body {
font: 16px/1.5 system-ui;
margin: 0;
color: #182b3c;
background: #f4f8fc;
}
header,
main {
max-width: 900px;
margin: auto;
padding: 20px;
}
header {
border-bottom: 1px solid #cbd5e1;
}
a {
color: #075985;
}
button,
input,
textarea,
select {
font: inherit;
padding: 8px;
margin: 4px;
}
button {
cursor: pointer;
}
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
padding: 10px;
border: 1px solid #cbd5e1;
text-align: left;
vertical-align: top;
}
pre,
code {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.pass {
color: #166534;
}
.fail,
[role="alert"] {
color: #a01818;
}
section {
margin: 16px 0;
padding: 12px;
background: white;
border-radius: 8px;
}
nav {
display: flex;
gap: 16px;
}
export function run({ usesBrowserApi, usesCookies }) {
return {
hydration: Boolean(usesBrowserApi),
requestIsolation: Boolean(usesCookies),
};
}
export const examples = [
[
{ usesBrowserApi: true, usesCookies: false },
{ hydration: true, requestIsolation: false },
],
];
Runs with real Next.js on your computer: unzip, then npm install and npm run dev.
Why the broken version looks fine here
The simulator renders client components only in the browser, so there's no
server HTML to disagree with: paste the broken version into the lab and it
shows a time without any warning. That's exactly the kind of gap this lesson's
plan is for. On Day 7 you run the capstone with next dev and next build,
where the warning appears.
The failure to avoid
Assuming the simulator's silence means a component is safe. Every row in the
plan stands for a check that needs a real server: a page load in next dev for
hydration, two different callers for request isolation. If you already have
Node installed and want to try it now, download the capstone from Day 7 and run
npm run build && npm start; otherwise leave it for Day 7, which walks through
it.
Exercise
Extend the contract
Add cacheIsolation to the plan when sharedCache is true.
Edit lib/contract.js, then rerun the original cases. If the requested rule
changes an earlier result, update that expected value deliberately. Keep the
other cases. Add the acceptance cases to examples so the preview checks them too.
cacheIsolation is derived like the other flags and added to the plan, never
replacing them, so a project that uses all three gets all three checks. The
check it stands for is a two-caller test: load as one user, then as another,
and compare. A faster second load proves the cache works, not that it's safe.
Explain it without the code
Write the two-request experiment that would show a shared cache leaking
private data.
Going further
Read the Next.js guide for the framework boundary around this rule.
The preview runs code-playpad's Next.js simulation. Real caching, hydration,
authentication and persistence require the real-server checks described on Day 7.
Completion is saved in this browser only. It does not measure mastery.