concrete/islands/island-ids
An island composes its own ids from `useIslandId()`, never React's `useId`, and only an island calls it.
An island composes its own ids from useIslandId(), never React's useId, and only an island calls 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
React's own id hook counts position from the root of the tree being rendered, and an
island's two renders have different roots: the server renders a whole section, the browser
hydrates a subtree rooted at one island marker. No prefix reconciles those, so an id minted
that way hydrates into an attribute mismatch in every visitor's console — on published
pages as much as under concrete dev. In the other direction, an id hook called outside
an island has no island to answer for and hands back the
same constant for every instance of the section on the page, which is a duplicate id
rather than a unique one.
Fix
Inside an island, compose ids from useIslandId() — the id the server minted for this
island, read back from its marker in the browser. In server-rendered markup, use what
already distinguishes the element: a slot id, a row key, nav.selfAnchor; pass that to an
island as a prop if the island needs it.
Before and after
"use client";
import type { IslandEditor } from "@homepages/concrete";
import { useId, useState } from "react";
export const editor = { live: true } satisfies IslandEditor;
export default function Disclosure() {
const id = useId();
const [open, setOpen] = useState(false);
return (
<div>
<button aria-controls={`${id}-panel`} aria-expanded={open} onClick={() => setOpen(!open)} />
<p id={`${id}-panel`} hidden={!open} />
</div>
);
}"use client";
import { useIslandId } from "@homepages/concrete";
import type { IslandEditor } from "@homepages/concrete";
import { useState } from "react";
export const editor = { live: true } satisfies IslandEditor;
export default function Disclosure() {
const id = useIslandId();
const [open, setOpen] = useState(false);
return (
<div>
<button aria-controls={`${id}-panel`} aria-expanded={open} onClick={() => setOpen(!open)} />
<p id={`${id}-panel`} hidden={!open} />
</div>
);
}