feat(renderers): add action forms to Solid, Vue, and Svelte

Merged
KI
13d ago
+427-5

Problem

  • React has useAction(fn).Form. Solid, Vue, and Svelte had nothing like it (the renderers table said "Not yet"), so every form was wired to an action by hand.

Change

  • submitRendererActionForm(action, event) in @farm.js/core/renderer-client, called from a submit listener:
    • cancels the browser's submission
    • sends the fields plus the submitter's name and value as FormData
    • on failure, keeps the fields and leaves the error in the action
    • on success, resets the form
    • does nothing if a listener already called preventDefault()
  • Solid: useAction(fn).Form renders <form method="post">. Props pass through, and the app's onSubmit runs first.
  • Vue: useAction(fn).Form is a component. Attributes and listeners pass through, and the app's @submit runs first.
  • Svelte: createAction(fn).enhance is a use: action for a form the app writes (<form method="post" use:save.enhance>).
  • Custom renderers can call the same helper (documented).

Safety and compatibility

  • Additive: new exports and new properties only.
  • method="post" keeps field values out of the URL when a submit goes native.
  • Known gap, not changed here: Farm's pre-hydration submit hold is emitted only in dev. In a production build, a submit made before hydration posts natively, for every renderer. It will get its own PR.

Verification

  • vitest run src/__tests__/renderer-client.test.ts (core): 12 passed. New: fields + submitter, reset on success, error kept on failure, a cancelled submit left alone.
  • pnpm test in farm-vue (70 passed), farm-solid (49), and farm-svelte (47). New binding tests in each.
  • tsc --noEmit for core, farm-vue, and farm-solid, plus pnpm run type-check for farm-svelte: all clean.
  • oxfmt --check and oxlint on changed files: clean.
  • Chrome, examples/vue-renderer with a temporary form page, not committed:
    • farm dev: success, reset, error, and fields kept on failure all pass, and a submit held before hydration replays.
    • farm build --preset node-server: the same post-hydration cases pass.
  • Svelte use:save.enhance and Vue <save.Form> template syntax both compiled. The app's onsubmit runs before enhance, checked in jsdom.

Not verified:

  • No real-browser run for Solid or Svelte (jsdom only).
  • Docs site build.

Documentation and release

  • docs/renderers: table row filled in, new "Action forms" section, and a custom-renderer note.
  • Solid, Vue, and Svelte pages: the boundary notes now link to it.

Summary by cubic

Adds action forms to Solid, Vue, and Svelte, mirroring React's useAction().Form. Previously, forms in these renderers had to be wired to actions by hand.

  • New submitRendererActionForm(action, event) helper in @farm.js/core/renderer-client is shared across renderers and callable by custom ones.
  • It cancels the browser's submission, sends fields plus the submitter's name and value as FormData, resets the form on success, keeps fields and the error on failure, and does nothing if a listener already called preventDefault().
  • Solid and Vue expose useAction(fn).Form rendering <form method="post">; Svelte exposes createAction(fn).enhance as a use: action. App-provided onSubmit/@submit handlers run first.
  • Additive only: new exports and properties, no breaking changes.

Known gap

  • A form submitted before hydration posts natively in production builds for all renderers; the pre-hydration submit hold is emitted in dev only. This will be addressed in a follow-up PR.