feat(farm-leaf): hydrate client components as islands
Merged
KI
11d ago+403+403+012345678901234567890123456789-50-50-01234567890123456789
Problem
Farm 0.1.84 hydrates client components as islands on any renderer that opts in (farming-labs/farm.js#3158), and leaf doesn't opt in yet. A client component used in a server page either hydrates with the whole page or not at all.
Change
packages/farm-leaf/src/index.ts:capabilities.islands, andclient:load,client:idle,client:visibleandclient:interactiontyped on leaf's JSX throughFarmIslandAttributes.packages/farm-leaf/src/server.ts:withIsland,wrapClientGraphandisolateServerPageGraph.withIslandwrites whatresolveFarmIslandreturns: the island element around the component, and the scripts that carry its props. Inside a tree that already hydrates as one root, it renders the component plain.packages/leaf/src:createContextanduseContext, which that needs, on the server and in the browser.app/:experimental.isolatedClientHydration: "enabled", an Islands link inlayout.leaf, and an/islandspage with three counters (client:load, the module'sisland = "idle",client:visible) that get aDateand aMapas props.- No browser code in farm-leaf: Farm's islands runtime hydrates each island with farm-leaf/client's
createElementandhydrateRoot. - Tests:
packages/farm-leaf/test/server.test.ts: 6 cases forwithIsland, plusislandsin the descriptor conformance.e2e/custom-renderer.spec.ts: each strategy hydrates on its own with its props intact, and a client navigation starts and ends the page's islands.
- README: islands in the feature list and the file table, and step 5 of "Make it yours".
Safety and compatibility
withIslandimportsresolveFarmIsland, new in Farm 0.1.84, so the app and farm-leaf move to@farm.js/coreand@farm.js/cli0.1.84, farm-leaf's peer floor rises to>=0.1.84, and@farm.js/renderer-testsmoves to 0.1.0-beta.3, which acceptscapabilities.islands.- Pages without client components, and apps that leave
isolatedClientHydrationoff, render as before.
Verification
With main (#2) merged in, against @farm.js/core and @farm.js/cli 0.1.84 installed from npm (pnpm install --frozen-lockfile):
pnpm type-check: passes in all three projects.pnpm test: 56 passed.pnpm test:e2e(production build) andpnpm test:e2e:dev: 19 passed each, with installed Chrome.
Documentation and release
README updated. It links Farm's Islands docs. No package release: farm-leaf is private.