diff --git a/.changeset/solid-form-solid-2.md b/.changeset/solid-form-solid-2.md new file mode 100644 index 0000000000..496ceb38aa --- /dev/null +++ b/.changeset/solid-form-solid-2.md @@ -0,0 +1,11 @@ +--- +'@tanstack/solid-form': patch +--- + +BREAKING: `@tanstack/solid-form` now targets Solid 2 and no longer supports Solid 1. + +Migration: + +- upgrade to Solid 2 (`solid-js` and `@solidjs/web` 2.0) +- import `render` and JSX types from `@solidjs/web` instead of `solid-js/web` +- `useSelector` and `useStore` are now exported by `@tanstack/solid-form` itself, which no longer depends on `@tanstack/solid-store` diff --git a/docs/framework/solid/guides/async-initial-values.md b/docs/framework/solid/guides/async-initial-values.md index e0197a3711..9bf46711f2 100644 --- a/docs/framework/solid/guides/async-initial-values.md +++ b/docs/framework/solid/guides/async-initial-values.md @@ -4,13 +4,12 @@ title: Async Initial Values --- Forms often edit data loaded from an API. A server-state library such as -TanStack Query should own fetching, caching, loading, and retries; TanStack Form +TanStack Query (`@tanstack/solid-query` v6 for Solid 2) should own fetching, caching, loading, and retries; TanStack Form should own the editable copy. -There are two supported ways to provide async initial values: wait to create the -form until the data is ready, or create it immediately with complete fallback -values. Choose the approach that best matches the loading experience your UI -needs. +In Solid 2, wait to create the form until the data is ready. Query data is +async, so don't read it inside the `createForm` options: those options are read +when the form is created, before the data has loaded. ## Wait for data before creating the editor @@ -19,13 +18,13 @@ Render a loading or error state first, then mount a component whose ```tsx // UserPage.tsx -import { Show } from 'solid-js' -import { createQuery } from '@tanstack/solid-query' +import { Errored, Loading, Show } from 'solid-js' +import { useQuery } from '@tanstack/solid-query' import { UserEditor } from './UserEditor' import type { User } from './types' export function UserPage(props: { userId: string }) { - const userQuery = createQuery(() => ({ + const userQuery = useQuery(() => ({ queryKey: ['user', props.userId], queryFn: async (): Promise => { const response = await fetch(`/api/users/${props.userId}`) @@ -34,14 +33,13 @@ export function UserPage(props: { userId: string }) { })) return ( - Could not load the user.

} - > - Loading…

}> - {(user) => } -
-
+ Could not load the user.

}> + Loading…

}> + + {(user) => } + +
+
) } ``` @@ -76,70 +74,10 @@ export function UserEditor(props: { user: User }) { } ``` -This pattern is useful when no form state is needed during loading. The keyed -`Show` recreates the editor when a different user object arrives. - -## Create the form before data arrives - -You can instead call `createForm` in the same component as `createQuery`. -Provide a static, shape-complete fallback so `defaultValues` are never -`undefined`. - -```tsx -import { Show } from 'solid-js' -import { createQuery } from '@tanstack/solid-query' -import { createForm } from '@tanstack/solid-form' -import type { User } from './types' - -const emptyUser: User = { - firstName: '', - lastName: '', -} - -export function UserPage(props: { userId: string }) { - const userQuery = createQuery(() => ({ - queryKey: ['user', props.userId], - queryFn: async (): Promise => { - const response = await fetch(`/api/users/${props.userId}`) - return response.json() - }, - })) - - const form = createForm(() => ({ - defaultValues: userQuery.data ?? emptyUser, - onSubmit: async ({ value }) => { - await fetch('/api/users', { - method: 'PUT', - headers: { 'content-type': 'application/json' }, - body: JSON.stringify(value), - }) - }, - })) - - return ( - Could not load the user.

} - > - Loading…

}> -
{ - event.preventDefault() - form.handleSubmit() - }} - > - {/* fields */} -
-
-
- ) -} -``` - -Because both integrations receive accessors, reading `userQuery.data` inside -the form options accessor keeps the options reactive. When query data replaces -the fallback, TanStack Form applies the new `defaultValues` to untouched fields -while preserving fields the user has already touched. +In Solid 2, query data is async: reading `userQuery.data` before it has loaded +suspends to the nearest `Loading` boundary. The keyed `Show` creates the editor +once the user has loaded, and recreates it when a different user object +arrives. This is the approach demonstrated by the repository's `examples/solid/query-integration` example. @@ -147,14 +85,12 @@ This is the approach demonstrated by the repository's ## Background refetches and record changes `defaultValues` establish the form's baseline; they are not a fully controlled -`values` prop. In the fallback pattern, later `defaultValues` updates use the -same touched-field-preserving behavior. +`values` prop. If background refetches arrive while a user is editing, decide at the product level whether to keep local edits, prompt before replacing them, or call `form.reset(nextValues)` deliberately. Do not overwrite in-progress input merely because a query refreshed. -When switching to a different record, either recreate a keyed editor as in the -first pattern or deliberately reset the existing form. Otherwise, touched -values from the previous record can be preserved when the new defaults arrive. +When switching to a different record, either recreate a keyed editor as above +or deliberately reset the existing form. diff --git a/docs/framework/solid/guides/validation.md b/docs/framework/solid/guides/validation.md index c1bcd6a4d9..7ba85c411a 100644 --- a/docs/framework/solid/guides/validation.md +++ b/docs/framework/solid/guides/validation.md @@ -38,7 +38,7 @@ change and blur triggers. onInput={(event) => field().handleChange(event.currentTarget.valueAsNumber) } - aria-invalid={field().meta.isInvalid} + aria-invalid={field().meta.isInvalid ? 'true' : 'false'} /> {(error) => {error.message}} @@ -209,7 +209,7 @@ Use `watchFields` when one field's validity depends on another: value={field().value} onBlur={field().handleBlur} onInput={(event) => field().handleChange(event.currentTarget.value)} - aria-invalid={field().meta.isInvalid} + aria-invalid={field().meta.isInvalid ? 'true' : 'false'} /> )} diff --git a/docs/framework/solid/quick-start.md b/docs/framework/solid/quick-start.md index 4d645c76d1..9cb7845b1b 100644 --- a/docs/framework/solid/quick-start.md +++ b/docs/framework/solid/quick-start.md @@ -6,10 +6,11 @@ title: Quick Start TanStack Form is a headless, type-safe form library. It owns form state and validation while leaving markup, styling, and component choice to you. -Install the Solid adapter: +Install the Solid adapter. TanStack Form v2 for Solid requires Solid 2 +(`solid-js` and `@solidjs/web` 2.0): ```bash -npm install @tanstack/solid-form +npm install @tanstack/solid-form solid-js @solidjs/web ``` ## Create a form @@ -59,7 +60,7 @@ export function ProfileForm() { onInput={(event) => field().handleChange(event.currentTarget.value) } - aria-invalid={field().meta.isInvalid} + aria-invalid={field().meta.isInvalid ? 'true' : 'false'} /> {(error) => {error.message}} @@ -89,7 +90,7 @@ export function ProfileForm() { onInput={(event) => field().handleChange(event.currentTarget.valueAsNumber) } - aria-invalid={field().meta.isInvalid} + aria-invalid={field().meta.isInvalid ? 'true' : 'false'} /> )} diff --git a/docs/migrate-from-v1.md b/docs/migrate-from-v1.md index e08030e2fa..350ff74857 100644 --- a/docs/migrate-from-v1.md +++ b/docs/migrate-from-v1.md @@ -58,6 +58,8 @@ This page is a starting checklist for migrating React apps from v1 to v2. a CommonJS build and require Node.js 18 or newer. - Upgrade React to version 18 or newer. The v2 React adapter no longer supports React 17. +- Upgrade Solid to version 2 when using the Solid adapter. The v2 Solid + adapter no longer supports Solid 1. - Update CommonJS integrations to consume ESM. The v2 packages do not publish a CommonJS build and require Node.js 18 or newer. @@ -78,6 +80,21 @@ Form Composition relies on Vue 3.6 behavior to work correctly. Requiring it from the start lets the Vue adapter support Form Composition without adding a breaking minimum-version change later in the v2 release line. +## Solid version + +The v2 Solid adapter requires Solid 2 (`solid-js` and `@solidjs/web` 2.0). +Solid 1 is no longer supported, so upgrade Solid before migrating. The +[Solid 2 docs](https://v2.solidjs.com) cover upgrading Solid itself. At the +time of writing, Solid 2 is available as a release candidate. + +In Solid 2 code that uses the adapter: + +- Import `render` and the JSX types from `@solidjs/web` instead of + `solid-js/web`. +- `useSelector` (and the deprecated `useStore` alias) is exported from + `@tanstack/solid-form` itself, so the adapter no longer depends on + `@tanstack/solid-store`. + ## Package format The v2 core, framework, devtools, and server-adapter packages publish ESM diff --git a/docs/overview.md b/docs/overview.md index 5a85cfb25b..c1f94d24a3 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -336,7 +336,7 @@ In the example below, you can see TanStack Form in action with the Solid framewo ```tsx title="App.tsx" -import { render } from 'solid-js/web' +import { render } from '@solidjs/web' import { createForm } from '@tanstack/solid-form' import { FieldInfo } from './FieldInfo.tsx' @@ -398,7 +398,7 @@ function App() { onInput={(event) => field().handleChange(event.currentTarget.value) } - aria-invalid={field().meta.isInvalid} + aria-invalid={field().meta.isInvalid ? 'true' : 'false'} /> @@ -418,7 +418,7 @@ function App() { onInput={(event) => field().handleChange(event.currentTarget.value) } - aria-invalid={field().meta.isInvalid} + aria-invalid={field().meta.isInvalid ? 'true' : 'false'} /> diff --git a/examples/solid/array/package.json b/examples/solid/array/package.json index 11c543804f..ae62ca62ae 100644 --- a/examples/solid/array/package.json +++ b/examples/solid/array/package.json @@ -9,12 +9,13 @@ "test:types": "tsc" }, "dependencies": { + "@solidjs/web": "^2.0.0", "@tanstack/solid-form": "^2.0.0-alpha.3", - "solid-js": "^1.9.13" + "solid-js": "^2.0.0" }, "devDependencies": { + "@solidjs/vite-plugin": "^3.0.0", "typescript": "^6.0.2", - "vite": "^8.2.1", - "vite-plugin-solid": "^2.11.14" + "vite": "^8.2.1" } } diff --git a/examples/solid/array/src/index.tsx b/examples/solid/array/src/index.tsx index bd65e165fc..4eb57ba075 100644 --- a/examples/solid/array/src/index.tsx +++ b/examples/solid/array/src/index.tsx @@ -1,5 +1,5 @@ -import { For, Index, createMemo, createSignal } from 'solid-js' -import { render } from 'solid-js/web' +import { For, createMemo, createSignal } from 'solid-js' +import { render } from '@solidjs/web' import { createForm } from '@tanstack/solid-form' import './index.css' @@ -36,7 +36,7 @@ function ArrayForm(props: { items: Array }) { {(array) => (
    - + {(_, index) => ( {(field) => ( @@ -56,7 +56,7 @@ function ArrayForm(props: { items: Array }) { )} )} - +
)}
diff --git a/examples/solid/array/tsconfig.json b/examples/solid/array/tsconfig.json index a2048f7ae9..b1dcd46bf1 100644 --- a/examples/solid/array/tsconfig.json +++ b/examples/solid/array/tsconfig.json @@ -3,7 +3,7 @@ "allowImportingTsExtensions": true, "isolatedModules": true, "jsx": "preserve", - "jsxImportSource": "solid-js", + "jsxImportSource": "@solidjs/web", "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "moduleResolution": "Bundler", diff --git a/examples/solid/array/vite.config.ts b/examples/solid/array/vite.config.ts index 4095d9be50..6a1fe32b00 100644 --- a/examples/solid/array/vite.config.ts +++ b/examples/solid/array/vite.config.ts @@ -1,5 +1,5 @@ import { defineConfig } from 'vite' -import solid from 'vite-plugin-solid' +import solid from '@solidjs/vite-plugin' export default defineConfig({ plugins: [solid()], diff --git a/examples/solid/basic-splitting-form/package.json b/examples/solid/basic-splitting-form/package.json index 61c7f40898..e310310d9a 100644 --- a/examples/solid/basic-splitting-form/package.json +++ b/examples/solid/basic-splitting-form/package.json @@ -9,12 +9,13 @@ "test:types": "tsc" }, "dependencies": { + "@solidjs/web": "^2.0.0", "@tanstack/solid-form": "^2.0.0-alpha.3", - "solid-js": "^1.9.13" + "solid-js": "^2.0.0" }, "devDependencies": { + "@solidjs/vite-plugin": "^3.0.0", "typescript": "^6.0.2", - "vite": "^8.2.1", - "vite-plugin-solid": "^2.11.14" + "vite": "^8.2.1" } } diff --git a/examples/solid/basic-splitting-form/src/StringField.tsx b/examples/solid/basic-splitting-form/src/StringField.tsx index 3712a29a38..277f80c07f 100644 --- a/examples/solid/basic-splitting-form/src/StringField.tsx +++ b/examples/solid/basic-splitting-form/src/StringField.tsx @@ -9,7 +9,7 @@ interface StringFieldProps { export function StringField(props: StringFieldProps) { return ( -