fix(solid-form): generate an SSR-safe default formId #2263
main fromrefs/pull/2263/head·merged by crutchcorn(GitHub profile, opens in a new tab) Changes#
When no formId is configured, createForm provides no fallback, so FormApi generates a random uuid() — seeded from Math.random(), and therefore different between the server render and the client render. Binding that generated id produces a hydration mismatch under SolidStart:
const form = createForm(() => ({ defaultValues: { firstName: '' } }))
<form id={form.formId}> {/* server: "d8efe189-…" client: "4b1c07a2-…" */}
An explicitly provided formId was already forwarded and is unchanged by this PR.
This is the same bug as #2254, which #2259 fixed for Vue. Solid is the remaining adapter with an SSR story that hadn't had the treatment the others already have:
react-form/src/useFormId.ts—React.useId, falling back touseUUIDon React 17preact-form/src/useFormId.ts—useIdfrompreact/hooksvue-form/src/useFormId.ts— Vue'suseId(#2259)
Solid's counterpart is createUniqueId(), which derives the id from the hydration context when one is present, so both renders agree. packages/solid-form/src/createForm.tsx now uses it for the default.
Test plan#
packages/solid-form/tests/createFormId.test.tsx covers both branches — an explicit formId is returned unchanged, and the default comes from Solid's id sequence rather than a random uuid. Before the change the second test fails with:
expected 'd8efe189-c90f-4667-ac96-e9685217a6a4' to match /^cl-\d+$/
The first test passes both before and after, which is the evidence that explicit ids were never affected.
Full @tanstack/solid-form suite passes (46 tests, 5 files), tsc --noEmit is clean, and eslint ./src ./tests reports no new problems.
One thing worth flagging#
I wasn't able to assert the server/client round-trip directly the way vue-form/tests/useFormId.test.tsx does. Under solid-form's current vitest config, solid-js/web resolves to the client build — isServer is false and renderToString() returns undefined — so an SSR render can't be exercised without a second vitest project configured with server conditions and solid({ ssr: true }).
Rather than grow this PR into a test-infrastructure change, the test pins the default to Solid's id sequence, which is the property that makes hydration agree. Happy to add the SSR project setup here or in a follow-up if you'd prefer the stronger assertion — just say which.
Summary by CodeRabbit#
Bug Fixes
- Improved server-side rendering and hydration reliability for Solid forms with stable default form IDs.
- Explicitly configured form IDs continue to work unchanged.
Tests
- Added coverage for custom form IDs and hydration-safe default IDs.
- 1
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In @.changeset/great-pugs-shave.md: - Line 5: Update the changeset description to state that createForm lacked an SSR-safe fallback formId when options.formId was not provided, while acknowledging explicit formId values were already forwarded. Capitalize React, Preact, and Vue.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
a9093e8e-c3b3-46d7-9424-841669e144dc📥 Commits
Reviewing files that changed from the base of the PR and between 028fcdd2fac4b97963642535c18610b1e8f9d07c and 3b92536dc4011e2d93be333dec8776e8533cb3d4.
📒 Files selected for processing (3)
.changeset/great-pugs-shave.mdpackages/solid-form/src/createForm.tsxpackages/solid-form/tests/createFormId.test.tsx
@@ -0,0 +1,5 @@1+---2+'@tanstack/solid-form': patch3+---4+5+Generate the default `formId` with Solid's `createUniqueId` so it is SSR-safe. Previously `createForm` never passed a `formId`, so `FormApi` fell back to a random uuid that differed between the server render and the client render, and binding it (`<form id={form.formId}>`) produced a hydration mismatch under SolidStart. Mirrors the existing behaviour of the react, preact and vue adapters.📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the changeset description.
Line 5 says that
createFormnever passed aformId, but explicitoptions.formIdvalues were already forwarded. Limit the statement to the missing fallback case. Also capitalizeReact,Preact, andVue.Proposed wording
-Generate the default `formId` with Solid's `createUniqueId` so it is SSR-safe. Previously `createForm` never passed a `formId`, so `FormApi` fell back to a random uuid that differed between the server render and the client render, and binding it (`<form id={form.formId}>`) produced a hydration mismatch under SolidStart. Mirrors the existing behaviour of the react, preact and vue adapters. +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. This mirrors the existing behaviour of the React, Preact, and Vue adapters.📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
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. This mirrors the existing behaviour of the React, Preact, and Vue adapters.🧰 Tools
🪛 LanguageTool
[uncategorized] ~5-~5: “React” is a proper noun and needs to be capitalized. Context: .... Mirrors the existing behaviour of the react, preact and vue adapters.
(A_GOOGLE)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.changeset/great-pugs-shave.md at line 5, Update the changeset description to state that createForm lacked an SSR-safe fallback formId when options.formId was not provided, while acknowledging explicit formId values were already forwarded. Capitalize React, Preact, and Vue.Source: Linters/SAST tools
✅ Addressed in commit c3d1e40
Good catch — corrected in c3d1e401. Explicit
formIdvalues were always forwarded; only the fallback was missing, and the changeset now says that. Framework names capitalized in both the changeset and the source comment.Worth noting the test file already documented this:
uses the provided formId when one is givenpasses both before and after the fix, so the explicit path was never affected.View your CI Pipeline Execution ↗ for commit c3d1e40157c96b84f52e78ef7fb9f727ba52eead
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 1m 28s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 8s View ↗
☁️ Nx Cloud last updated this comment at
2026-08-08 22:07:30UTCMore templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-large-form
- @tanstack/form-example-angular-multi-step-wizard
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-standard-schema
- @tanstack/form-example-lit-array
- @tanstack/form-example-lit-large-form
- @tanstack/form-example-lit-multi-step-wizard
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-standard-schema
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-preact-multi-step-wizard
- @tanstack/form-example-preact-simple
- @tanstack/form-example-react-array
- @tanstack/form-example-react-compiler
- @tanstack/form-example-react-composition
- @tanstack/form-example-react-devtools
- @tanstack/form-example-react-dynamic
- @tanstack/form-example-react-expo
- @tanstack/field-errors-from-form-validators
- @tanstack/form-example-react-large-form
- @tanstack/form-example-react-multi-step-wizard
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-next-server-actions-zod
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-remix
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-standard-schema
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-ui-libraries
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-devtools
- @tanstack/form-example-solid-large-form
- @tanstack/form-example-solid-multi-step-wizard
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-multi-step-wizard
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-large-form
- @tanstack/form-example-svelte-multi-step-wizard
- @tanstack/form-example-svelte-simple
- @tanstack/form-example-svelte-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@2263@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@2263@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@2263@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@2263@tanstack/preact-form
npm i https://pkg.pr.new/@tanstack/preact-form@2263@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@2263@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@2263@tanstack/react-form-nextjs
npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2263@tanstack/react-form-remix
npm i https://pkg.pr.new/@tanstack/react-form-remix@2263@tanstack/react-form-start
npm i https://pkg.pr.new/@tanstack/react-form-start@2263@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@2263@tanstack/solid-form-devtools
npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2263@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@2263@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@2263commit:
c3d1e40crutchcorn(GitHub profile, opens in a new tab) approved these changes
crutchcorn(GitHub profile, opens in a new tab) closed this
:warning: Please install the
to ensure uploads and comments are reliably processed by Codecov.
Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 97.48%. Comparing base (
6892ed0) to head (c3d1e40). :warning: Report is 267 commits behind head on main. :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.Additional details and impacted files
@@ Coverage Diff @@ ## main #2263 +/- ## ========================================== + Coverage 90.35% 97.48% +7.13% ========================================== Files 38 5 -33 Lines 1752 159 -1593 Branches 444 13 -431 ========================================== - Hits 1583 155 -1428 + Misses 149 4 -145 + Partials 20 0 -20:umbrella: View full report in Codecov by Harness. :loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
createFormnow uses Solid’screateUniqueIdfor SSR-safe default form IDs. ExplicitformIdvalues remain unchanged. Tests cover both ID paths, and a patch changeset documents the update.Changes#
Solid form ID generation
packages/solid-form/src/createForm.tsxcreateFormgenerates a fallback ID withcreateUniqueIdwhen noformIdis configured and passes the selected ID toFormApi.packages/solid-form/tests/createFormId.test.tsx,.changeset/great-pugs-shave.mdcl-<n>format. The changeset documents the SSR-safe ID behavior.Estimated code review effort: 2 (Simple) | ~10 minutes
Possibly related PRs
formIdgeneration for framework-specific form initialization.🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share