feat(farm-leaf): recover from hydration errors in production
Problem
Farm creates a root with createRoot() over markup it didn't render: the server's markup when hydrateRoot() throws, and the last page's when a navigation replaces the root. leaf's root renders next to what's already in its container, so in that case the page shows up twice. Without a root that replaces the markup, leaf also can't opt in to Farm's production hydration fallback (farming-labs/farm.js#3140).
Change
farm-leaf/client'screateRoot()empties the container before creating a leaf root, as Farm's official renderers do.- The descriptor sets
capabilities.hydrationFallback: true. On the Farm release after 0.1.81, a production page whose hydration throws is rendered in the browser, as development already does. 0.1.81 ignores the key. - The README's "Make it yours" step says to keep that
createRoot()behavior or drop the capability.
Verification
pnpm --filter farm-leaf exec vitest run test/client.test.ts: the newrenders a new root in place of the markup already in its containerfails without thecreateRoot()change (<span>Client render</span><p>Server markup</p>) and passes with it.pnpm type-check: clean against@farm.js/core0.1.81's types.pnpm test: 26 passed.pnpm build:packages: ok.pnpm test:e2eandpnpm test:e2e:dev(Chrome channel locally): 13 passed each.
Not covered yet: Farm's new shared client conformance check and an end-to-end /recovers page. Both need the Farm release after 0.1.81, so they come with that version bump.
Summary by cubic
Fixes farm-leaf rendering the page twice when Farm creates a root over markup it didn't render: the server's markup when hydrateRoot() throws, and the last page when a navigation replaces the root. createRoot() now empties its container first, and the descriptor sets capabilities.hydrationFallback: true so a production page whose hydration throws is rendered in the browser, as development already does.
- Farm reads the capability after 0.1.81; 0.1.81 ignores it.
- A new client test verifies the root replaces existing markup, and the README's "Make it yours" step says to keep that behavior or drop the capability.