concrete/render/sentinel-text
Rendered text is `[object Object]` or a bare `null`, `undefined` or `NaN`.
Rendered text is [object Object] or a bare null, undefined or NaN.
Graded by the render stage of concrete check, in the render venue. A violation reports this id and the file it failed at — see every rule and concrete check.
Reason
[object Object], a bare null or a NaN on the page is a value that reached the DOM
without a formatter. It is always a bug and never a design, which is why it is graded
rather than left to review: a slot holds a typed value with an empty
state, and the moment you interpolate it into text yourself you have taken on both the
formatting and the empty branch. The stage renders the synthesized empties too, so the
state that produces the sentinel is one the corpus reaches even when no fixture does.
Fix
Render the value through its primitive, which formats it and owns the empty branch, or
format it yourself and branch on present first. Arithmetic over an empty number slot is
where NaN comes from.
Before and after
import { number, Section, section, Slot, text } from "@homepages/concrete";
export const Stats = section(
{
key: "stats",
label: "Stats",
slots: { beds: number({ label: "Beds" }), note: text.short({ label: "Note" }) },
},
({ slot }) => (
<Section>
<Slot.Text slot={slot.note} as="p" />
{/* An empty number slot makes this NaN. */}
<p>{Number(slot.beds.value) * 2} sleeping spaces</p>
</Section>
),
);import { number, Section, section, Slot, text } from "@homepages/concrete";
export const Stats = section(
{
key: "stats",
label: "Stats",
slots: { beds: number({ label: "Beds" }), note: text.short({ label: "Note" }) },
},
({ slot }) => (
<Section>
<Slot.Text slot={slot.note} as="p" />
<Slot.Number slot={slot.beds} as="p" format={(value) => `${String(value * 2)} sleeping spaces`} />
</Section>
),
);