Concrete
Rulesserver

concrete/server/no-nondeterminism

Server-rendered code reads no clock and no random source.

Server-rendered code reads no clock and no random source.

Graded by the lint stage of concrete check, in the lint venue. A violation reports this id and the file it failed at — see every rule and concrete check.

Reason

A section's render is a pure function of its bindings, and two processes run it: the publisher that writes the page and the editor that redraws the canvas. They must produce the same HTML from the same input, because the editor diffs against what was published — so a clock read or a random value makes the two disagree on every render, and the page drifts under the person editing it. The server half has no moment at which "now" means anything: the render happens long before a visitor arrives.

Fix

Take the value from somewhere deterministic. A date the page states is a fact or a slot value; a value that genuinely depends on when someone is looking belongs in a "use client" island, which runs in the browser and whose output is nobody's content hash. new Date(listedAt) parses a value you were given and is fine.

Before and after

import { Section, section, Slot, text } from "@homepages/concrete";

export const Footer = section(
  { key: "footer", label: "Footer", slots: { tagline: text.short({ label: "Tagline" }) } },
  ({ slot }) => (
    <Section as="footer">
      <Slot.Text slot={slot.tagline} as="p" />
      <small>© {new Date().getFullYear()}</small>
    </Section>
  ),
);
import { fact, Section, section, Slot, text } from "@homepages/concrete";

export const Footer = section(
  {
    key: "footer",
    label: "Footer",
    slots: {
      tagline: text.short({ label: "Tagline" }),
      notice: text.short({ label: "Copyright notice", source: fact.property.address.city }),
    },
  },
  ({ slot }) => (
    <Section as="footer">
      <Slot.Text slot={slot.tagline} as="p" />
      <Slot.Text slot={slot.notice} as="small" />
    </Section>
  ),
);

On this page