concrete/relations/section-cycle
The placed sections read each other in a loop; a template's sections form a DAG.
The placed sections read each other in a loop; a template's sections form a DAG.
Graded by the relations stage of concrete check, in the probe venue. A violation reports this id and the file it failed at — see every rule and concrete check.
Reason
A relationship is written on the slot that depends, in that section's own module, and the ref it reads comes off the other section's value — so a section reading another is a module importing another. Two sections that read each other are therefore two modules that import each other, and a value taken at module scope inside an import cycle is not there yet: whichever module the bundler evaluates second gets a half-built section to take a ref from.
That is why the DAG is set at the SECTION level rather than the slot level. Inside one
section the ordering is acyclic by construction, and one rule over the whole graph is what
keeps every edge — a compute's and a fill decision's alike — under the same guarantee.
Fix
Cut one direction. The question to ask is which of the two slots actually owns the
relationship: one of them is derived from the other, and the other is the source. Make the
derived one compute({ reads }) and leave the source authored or fact-bound.
Where both really do need the same value, neither reads the other — they each read the facts, which no section owns.
Before and after
import { compute, Section, section, Slot, text } from "@homepages/concrete";
// Two sections mirroring each other: the loop has no starting value.
const Footer = section(
{
key: "footer",
label: "Footer",
slots: {
tagline: text.short({
label: "Tagline",
cap: 40,
// Reads the hero, which reads the footer.
source: compute({ reads: [{ section: "hero", slot: "headline" } as const] }, (headline) => String(headline ?? "")),
}),
},
},
({ slot }) => (
<Section>
<Slot.Text slot={slot.tagline} as="p" />
</Section>
),
);
export const Hero = section(
{
key: "hero",
label: "Hero",
slots: {
headline: text.medium({
label: "Headline",
cap: 60,
source: compute({ reads: [Footer.slots.tagline] }, (tagline) => tagline ?? ""),
}),
},
},
({ slot }) => (
<Section>
<Slot.Text slot={slot.headline} as="h1" />
</Section>
),
);import { compute, fact, Section, section, Slot, text } from "@homepages/concrete";
// One direction: the hero owns the headline, the footer mirrors it.
export const Hero = section(
{
key: "hero",
label: "Hero",
slots: { headline: text.medium({ label: "Headline", cap: 60, source: fact.property.address.street }) },
},
({ slot }) => (
<Section>
<Slot.Text slot={slot.headline} as="h1" />
</Section>
),
);
export const Footer = section(
{
key: "footer",
label: "Footer",
slots: {
tagline: text.short({
label: "Tagline",
cap: 40,
source: compute({ reads: [Hero.slots.headline] }, (headline) => headline ?? ""),
}),
},
},
({ slot }) => (
<Section>
<Slot.Text slot={slot.tagline} as="p" />
</Section>
),
);