feat(renderers): add action forms to Solid, Vue, and Svelte
Merged
KI
13d ago+427+427+012345678901234567890123456789-5-5-0123456789
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 asubmitlistener:- 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).Formrenders<form method="post">. Props pass through, and the app'sonSubmitruns first. - Vue:
useAction(fn).Formis a component. Attributes and listeners pass through, and the app's@submitruns first. - Svelte:
createAction(fn).enhanceis ause: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 testin farm-vue (70 passed), farm-solid (49), and farm-svelte (47). New binding tests in each.tsc --noEmitfor core, farm-vue, and farm-solid, pluspnpm run type-checkfor farm-svelte: all clean.oxfmt --checkandoxlinton changed files: clean.- Chrome,
examples/vue-rendererwith 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.enhanceand Vue<save.Form>template syntax both compiled. The app'sonsubmitruns beforeenhance, 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-clientis 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 calledpreventDefault(). - Solid and Vue expose
useAction(fn).Formrendering<form method="post">; Svelte exposescreateAction(fn).enhanceas ause:action. App-providedonSubmit/@submithandlers 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.