feat(farm-leaf): map flat route files and read leaf's hydrate pragma

Merged
KI
11d ago
+352-48

Problem

Farm's renderer interface gains routes() and hydration (farming-labs/farm.js#3154), and leaf doesn't use them yet: every route is a page.tsx or page.leaf folder file, and a .leaf file can only hydrate through export const hydrate = true.

Change

  • packages/farm-leaf/src/index.ts: routes() keeps Farm's folders and maps app/src/app/guides/ as flat files. index.leaf is /guides, harvest.leaf is /guides/harvest, [crop].leaf is dynamic, _layout.leaf is the folder's layout, other _ files are components, and a .client name hydrates. hydration.resolve() reads // @hydrate [load|idle|visible|interaction|false] from a .leaf file.
  • app/src/app/guides/: six files that use both, the same ones as examples/custom-renderer in farm.js.
  • packages/farm-leaf/test/descriptor.test.ts: the rules and the pragma.
  • e2e/custom-renderer.spec.ts: 4 tests (flat pages in the layout, skipped files 404, which pages hydrate, client navigation inside the guides layout).
  • README: "Its own route files", and step 3 of "Make it yours" says both hooks are optional.

Safety and compatibility

Both hooks ship in Farm 0.1.83, so the app and farm-leaf move to @farm.js/core and @farm.js/cli 0.1.83, and farm-leaf's peer floor rises to >=0.1.83.

Verification

Against @farm.js/core and @farm.js/cli 0.1.83 installed from npm (pnpm install --frozen-lockfile):

  • pnpm type-check: passes in all three projects.
  • pnpm test: 32 passed (7 new).
  • pnpm test:e2e (production build) and pnpm test:e2e:dev: 17 passed each, with installed Chrome.

Documentation and release

README updated. No package release: farm-leaf is private.