Skip to content
Source
Sign inSign up
TanStack/form

fix(solid-form): generate an SSR-safe default formId #2263

Mergedharshit-d3v(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/2263/headmerged by crutchcorn(GitHub profile, opens in a new tab)

Showing 3 changed files with 51 additions and 2 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/great-pugs-shave.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/solid-form': patch
+---
+​
+Generate the default `formId` with Solid's `createUniqueId` so it is SSR-safe. Previously, when no `formId` was configured, `createForm` did not provide a fallback, so `FormApi` generated a random UUID that differed between the server render and the client render. Binding that generated id (`<form id={form.formId}>`) produced a hydration mismatch under SolidStart. An explicitly provided `formId` was already forwarded and is unchanged. This mirrors the existing behaviour of the React, Preact, and Vue adapters.
10 additions and 2 deletionspackages/solid-form/src/createForm.tsxModified
View file
@@ -1,5 +1,5 @@
import { FormApi, functionalUpdate } from '@tanstack/form-core'
-import { createComputed, onMount } from 'solid-js'
+import { createComputed, createUniqueId, onMount } from 'solid-js'
import { useSelector } from '@tanstack/solid-store'
import { Field, createField } from './createField'
import { FormGroup } from './createFormGroup'
@@ -240,6 +240,14 @@
) {
const options = opts?.()
+ /**
+ * `FormApi` falls back to `uuid()` when no `formId` is given, which differs
+ * between the server render and the client render. `createUniqueId` is
+ * Solid's SSR-safe counterpart, so binding the id (`<form id={form.formId}>`)
+ * no longer produces a hydration mismatch. Mirrors `useFormId` in the React,
+ * Preact, and Vue adapters.
+ */
+ const fallbackFormId = createUniqueId()
const api = new FormApi<
TParentData,
TFormOnMount,