concrete/islands/editor-reason
Every read of `inCanvas` that changes behavior carries an `editor-reason:` comment directly above it.
Every read of inCanvas that changes behavior carries an editor-reason: comment directly above it.
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
useEditor() tells an island it is in the canvas, and every fork on that flag is a place
where what the author sees stops being what a visitor gets. Sometimes that is right — a
fullscreen takeover would cover the page being edited — and sometimes it is a workaround
somebody left behind. The two look identical in the source, so
the island is made to say which it is, in a comment the
next reader can weigh.
Fix
Put a comment opening with editor-reason: directly above the fork, naming the
published-only behaviour it protects. If you cannot name one, the fork is not an escape
hatch: drop it and let the island behave in the canvas as it does on the page, or declare
the whole island editor = { live: false }.
Before and after
"use client";
import { useEditor } from "@homepages/concrete";
import type { IslandEditor } from "@homepages/concrete";
export const editor = { live: true } satisfies IslandEditor;
export default function Lightbox({ src }: { src: string }) {
const { inCanvas } = useEditor();
if (inCanvas) return <img src={src} alt="" />;
return <dialog open><img src={src} alt="" /></dialog>;
}"use client";
import { useEditor } from "@homepages/concrete";
import type { IslandEditor } from "@homepages/concrete";
export const editor = { live: true } satisfies IslandEditor;
export default function Lightbox({ src }: { src: string }) {
const { inCanvas } = useEditor();
// editor-reason: the lightbox is a fullscreen takeover that would cover the page
// being edited, and nothing could be selected behind it.
if (inCanvas) return <img src={src} alt="" />;
return <dialog open><img src={src} alt="" /></dialog>;
}