Gate content behind the lead form
The brochure, the floor plans or the gallery should open only once a visitor has introduced themselves.
Goal
Hold the contact section's brochure link back until the visitor has sent the lead form — and keep the section editable while its owner is editing it.
Prerequisites
- Add a lead form: the form whose submission opens this gate.
- A
documentslot on that section for the brochure, stated in the fixture.
Steps
What this gate is, and what it is not
A published page is a static document on a CDN. Every byte it carries — an island's props included — is in the visitor's browser before any of your code runs, and devtools will show it to anyone who looks.
So this is a gate over what a visitor sees, not over what they can fetch. It is the right tool for shaping a visit and the wrong one for anything that must stay secret; nothing on a published page can be kept from a determined reader.
Record the unlock
One key in localStorage, written by the form island when a submission comes
back accepted:
declare const setStatus: (status: string) => void;
declare const result: { ok: boolean; simulated?: true };
export const UNLOCK_KEY = "unlocked:brochure";
if (result.ok) {
// Accepted, simulated or not: the unlock is a convenience, and a gate nobody
// can open in preview is a gate nobody can author against.
localStorage.setItem(UNLOCK_KEY, "1");
setStatus(result.simulated === true ? "simulated" : "sent");
}Branch on whether the submission was accepted, never on whether it was really
sent. There is no site config on a preview page, so every submission in the editor
canvas and in concrete dev reports itself simulated; a gate keyed on a real send
is one nobody can open on the surfaces you author from. Withholding the key buys
no secrecy either — see above.
Storage is scoped to the origin, and a published site is its own origin, so the key is readable by that site's pages and by nothing else.
Withhold the value, keep the marker
The gated content belongs to an island, and the locked branch renders the slot's
own primitive with no value to follow — never nothing at all. A slot that vanishes
from the DOM is a slot the editor cannot select, which is
render/missing-slot-marker, reported
against the fixture where it disappeared.
"use client";
import { Slot, useEditor, type DocumentSlot, type IslandEditor, type SlotBinding } from "@homepages/concrete";
import { useEffect, useState } from "react";
// Live, so the canvas hydrates it and the gate can stand down there.
export const editor = { live: true } satisfies IslandEditor;
export const UNLOCK_KEY = "unlocked:brochure";
export default function GatedBrochure({ slot }: { slot: SlotBinding<DocumentSlot> }) {
const { inCanvas } = useEditor();
const [unlocked, setUnlocked] = useState(false);
// In an effect, never during render: `localStorage` does not exist while the
// server renders, so reading it anywhere else makes the two renders disagree.
useEffect(() => {
setUnlocked(localStorage.getItem(UNLOCK_KEY) === "1");
}, []);
// editor-reason: the gate must stand down in the canvas, or the author's own
// brochure link is missing from the page they came to edit.
if (!inCanvas && !unlocked) {
return <Slot.Download slot={slot} as="span">Send the form above to download the brochure.</Slot.Download>;
}
return <Slot.Download slot={slot}>Download the brochure (PDF)</Slot.Download>;
}The locked branch renders a span rather than an anchor, so there is no link to follow and the slot is still a selectable card in the editor — an unfilled document slot renders the same way, marked and without a URL. The state starts locked so the server render and the browser's first render agree; the effect flips it afterwards.
Keep the canvas editable
inCanvas is not optional here. Without it the site's owner opens their page in
the editor, the gate finds no key, and the content they came to edit is not on the
screen with no way to reach it. Every read of it that changes behaviour carries an
editor-reason: comment on the line above —
islands/editor-reason requires one, and
islands/no-editor-globals is what stops you
reaching for the canvas's own globals instead of useEditor.
The pairing matters: an island is hydrated in the canvas only when it declares
live, and a gate that is not live shows the canvas its locked server frame
forever.
Verify
Run concrete check — green means the marker survived both branches. Then, in
concrete dev, compare the two surfaces:
- The canvas shows the unlocked branch, always, because the island is live and
inCanvasis true there. - View live shows the locked branch, and sending the form unlocks it — the round trip is walkable in preview exactly as it is on a published page.
To reach either state without the form, drive the key from the browser console and
reload: localStorage.setItem("unlocked:brochure", "1") unlocks,
localStorage.removeItem("unlocked:brochure") re-locks.
