docs(rfcs): propose an opt-in islands interface for renderers

Merged
KI
11d ago
+457-0

Problem

Component islands work only with React. The pieces behind them are either written against React or sit behind an isReactRenderer check:

  • the server wrapper createFarmIsolatedClientBoundary;
  • the export transform;
  • the browser runtime's error boundary.

So a custom renderer can't use them. Its pages hydrate as one whole route, and async pages stay server-only.

Change

This adds RFC 0012, "An islands interface for renderers". It's a draft and there's no code change. It only adds to core; React, Preact, Solid, Vue and Svelte are unchanged.

  • The rule: core exposes, renderers opt in.
    • A renderer declares the capability in its descriptor (capabilities.islands) and exports the hook (withIsland).
    • Without the capability, core takes today's path. Acceptance requires byte-identical output for the official renderer examples.
    • If a renderer declares the capability but the export is missing, startup fails and names the export.
  • Built on islx, not a second copy in core. islx#91 (released in 0.0.28) has the wire format, the props codec, the restore on failure and a browser runtime without React, tested in Chrome on Preact, Vue, Svelte and Solid.
    • Server: resolveFarmIsland(props, reference) strips client:*, picks the strategy, names the island, and returns islx's parts: the value scripts, the <f-island> element and the props script. A renderer never hardcodes the wire format. farming-labs/islx#92 adds resolveIslandMarkup for this.
    • Browser: the generated entries start islx's createIslandRuntime, with hydrate built from the renderer's existing createElement and hydrateRoot, and Farm's own loadFarmIsolatedBoundary and scheduleFarmIslandHydration. The renderer writes no browser code for islands.
    • Props: islx's codec, so Date, Map, Set and server actions as well as JSON.
    • Navigation: islands.dispose(), then islands.hydrate() on the new page.
  • The renderer's part. withIsland(component, reference) is an optional server export. It writes the parts around the component in its own tree. Core also provides a FarmIslandAttributes type for the renderer's JSX types.
  • How an app marks islands:
    • "use client" marks the module.
    • A client:load|idle|visible|interaction attribute where the component is used sets that one island's strategy.
    • The RFC compares four places to put the marker and explains this choice.
  • Rollout: step 0 is islx#92, an islx release with it, and a pin bump (core pins @farm.js/islx 0.0.25). Then the interface, then examples/custom-renderer as the reference implementation.
  • Separate follow-ups, each needing its own go-ahead:
    • an official renderer adopting the interface (Solid is the cheapest check before calling the contract stable);
    • client:* for React;
    • isolatedClientHydration: "enabled" on non-React renderers, which needs a repro first;
    • other rendering-layer hooks exposed the same way.

Verification

  • Compiler behavior: I compiled <Counter client:visible start={1} /> on 2026-11-23 (Node 24.21.0):
    • oxc (Rolldown 1.3.3, react and preact import sources), babel-preset-solid 1.9.12 (dom and ssr), @vue/compiler-sfc 3.5.44 (client and SSR) and Svelte 5.56.8 (client and server) all pass it through as a prop. Vue's value is "".
    • Babel's plugin-transform-react-jsx 7.29.7 throws by default and works with throwIfNamespace: false.
  • TypeScript 5.9.3 with @types/react 19.2.13:
    • TS2322 without the type augmentation.
    • Accepted with the augmentation, and a typo gets "Did you mean".
  • The islx entries the RFC relies on: islx#92's branch passes 262 unit tests, and its Chrome e2e passes 73 with 3 skipped (existing dev-only and production-only tests), including 26 renderer tests on Preact, Vue, Svelte and Solid against the production build and the dev server.
  • Code references (loadFarmIsolatedBoundary, scheduleFarmIslandHydration, wrapWithIntegrationProviders, FarmRendererClientRoot.unmount, data-farm-solid-render-id, transformIsolatedClientBoundaryModule, assertFarmRendererServerModule, wrapClientGraph) were checked against main at 11af44060.
  • oxfmt --check (0.27.0) passes on both files.

Not verified:

  • Solid's island ids: a Solid withIsland could put data-farm-solid-render-id on the island element, which farm-solid's hydrateRoot already reads. That's read from the code, not run. It's the first thing the Solid follow-up checks.
  • The non-React isolatedClientHydration failure: read from the code, not run.
  • TypeScript checking outside React.
  • Bytes inside a Farm page. islx's measured 6.0 KB gzip client is from islx#91, not a Farm build.

Documentation and release

rfcs/README.md gets a row for 0012. 0011 is taken by #3064.

The /docs/renderers/custom link is live (#3127).