fix(react): mark islands as react client references
Problem
Code written for React Server Components detects a client component by React's marker, $$typeof === Symbol.for("react.client.reference"), before it calls a component outside a render. assistant-ui's MDX-to-Markdown route does this to leave interactive previews out. Islands carry only islx's own islx.react.client-reference symbol, so that code called them, and the island's useContext threw outside a render:
TypeError: Cannot read properties of null (reading 'useContext')
at Island (island-*.mjs)
On the assistant-ui docs on Farm, 33 Markdown mirrors returned 500 this way once their MDX samples became islands (farming-labs/farm.js#3043).
Change
createIsland also defines $$typeof as React's client reference symbol on the island component, next to islx's own marker.
Safety and compatibility
- React renders a function component whatever its
$$typeof(checked on react-dom 19.2.8renderToStringin production and development, no warnings), so rendering and hydration are unchanged. The browser build doesn't usecreateIsland. getClientReferenceand islx's own symbol are unchanged.- Only
$$typeofis set, not$$idor$$async, which only matter to a Flight bundler.
Verification
pnpm exec vitest run: 241 passed. The new test (carry React's client reference marker…) fails without the change.pnpm typecheck, plusoxfmtandoxlinton the changed files: clean.- assistant-ui docs production build with the same line patched into the built island chunk: Markdown mirrors went from 58 to 25 failing. The remaining 25 are
/elements/*pages without an MDX source, whose route throwsnotFound()(unrelated). 728 of 730 HTML routes return 200.
Documentation and release
CHANGELOG entry under Unreleased.
Summary by cubic
Islands now carry React's client reference marker ($$typeof), so code written for Server Components that walks element trees outside a render—such as an MDX-to-Markdown converter—skips them instead of calling them and crashing on their hooks.
createIslandsets$$typeoftoSymbol.for("react.client.reference")alongside islx's own marker.- Rendering and hydration are unchanged; React still renders a function component regardless of
$$typeof. - Added a regression test that fails without the change.