Skip to content

Add TanStack Form as the form layer and replace react-hook-form - #2574

Open
kmcginnes wants to merge 6 commits into
mainfrom
tanstack-form-query-editor
Open

kmcginnes wants to merge 6 commits into
mainfrom
tanstack-form-query-editor

Conversation

@kmcginnes

@kmcginnes kmcginnes commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Form handling is split today: one form runs on react-hook-form, and every other input uses hand-rolled state and validation. This PR adds TanStack Form with Zod as the one form layer, moves the query editor onto it, and removes react-hook-form.

User-facing: the query editor's Submit button now sits in a strip inside the text box's border instead of floating over the text. The button stays keyboard-focusable while a query runs. The box can still be dragged taller.

src/components/
├── form/                 # new form layer
│   ├── useAppForm.ts     # createFormHook: useAppForm, withForm, field parts
│   ├── fieldParts.tsx    # field.Wrapper, Label, Description, Error
│   ├── textControls.tsx  # field.TextArea, field.InputGroupTextarea
│   └── SubmitButton.tsx  # aria-disabled while it can't submit; asChild
├── FormItem.tsx          # layout helper, moved out of the deleted wrappers
├── FormError.tsx         # layout helper, moved out of the deleted wrappers
└── Form.tsx              # deleted, with react-hook-form and @hookform/resolvers

Each field part takes the same props as the shadcn primitive it wraps. Parts named Field* drop the prefix (Field is field.Wrapper); every other part keeps its name. field.Wrapper shares ids with its parts, so the bound control fills in id, name, value, onChange, onBlur, aria-invalid, and an aria-describedby that lists only the description and error on the page. A bound part used outside field.Wrapper throws.

 <QuerySearchTabContent>
-  useForm() + standardSchemaResolver   # plus a hand sync into queryTextAtom
+  useAppForm({ validationLogic: revalidateLogic(), validators: { onDynamic: querySchema } })
   <form>
-    <FormField><TextArea /></FormField>
-    <QuerySubmitButton className="absolute right-2 bottom-2" />
+    <form.AppField listeners={{ onChange: setQueryText }}>
+      <field.Wrapper>
+        <field.Label className="sr-only" />
+        <field.InputGroup>
+          <field.InputGroupTextarea />
+          <field.InputGroupAddon align="block-end">
+            <form.SubmitButton asChild><InputGroupButton /></form.SubmitButton>
+        <field.Error />

docs/agents/react.md now makes useAppForm with a Zod schema the rule for all user input, in a submit mode or an auto-save mode. docs/adr/20261110-tanstack-form-and-zod-for-user-input.md records the decision. Submit mode uses revalidateLogic() with validators.onDynamic, because plain validators.onSubmit doesn't show an error again when a value turns invalid after a failed submit.

Evidence

Before: the Submit button floated over the text box's bottom-right corner and became natively disabled while a query ran, which dropped keyboard focus to the page.

After:

Query editor with the Submit button in an input group strip below the text

Query editor dragged taller, with the Submit button still below the text

New tests (agent-tested) cover the field parts' ids, aria-describedby, data-invalid in both states, and the throw outside field.Wrapper. A query editor test presses Cmd+Enter twice while a query runs and expects one request.

Verified live (agent-tested): in Chrome and Safari against a public SPARQL endpoint: Cmd+Enter and Ctrl+Enter each send one query, plain Enter adds a newline, the Submit click sends one query, and focus stays on Submit while the query runs. Repeat clicks and shortcuts during a run send nothing. The text and results survive switching sidebar tabs, Cancel works, and dragging the box taller grows the group.

Merge Danger

Door: two-way

Impact: query editor

The query editor is the only screen that changes. Removing react-hook-form touches no other screen: FormItem and FormError keep their markup in their new files. No saved data, config, or URL is involved.

Related


🤖 Written by an AI agent on my behalf.

@kmcginnes
kmcginnes force-pushed the tanstack-form-query-editor branch from 752c4e5 to ccccc62 Compare November 18, 2026 00:31
Frees the components/form import path, which resolved to Form.tsx on case-insensitive filesystems.

Layer: 1-tanstack-form-query-editor
Layer: 1-tanstack-form-query-editor
Layer: 1-tanstack-form-query-editor
The query editor was its last user. FormItem and FormError, the layout helpers older fields still use, move to their own files.

Layer: 1-tanstack-form-query-editor
Layer: 1-tanstack-form-query-editor
Adds asChild to form.SubmitButton and the field.InputGroup parts it sits in.

Layer: 1-tanstack-form-query-editor
@kmcginnes
kmcginnes force-pushed the tanstack-form-query-editor branch from ccccc62 to 697dd2d Compare November 25, 2026 00:43
@kmcginnes kmcginnes changed the title Add TanStack Form as the form layer and move the query editor onto it Add TanStack Form as the form layer and replace react-hook-form Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant