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)

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 to useUUID on React 17
  • preact-form/src/useFormId.ts — useId from preact/hooks
  • vue-form/src/useFormId.ts — Vue's useId (#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. Review Change Stack

      📝 Walkthrough

      Walkthrough

      createForm now uses Solid’s createUniqueId for SSR-safe default form IDs. Explicit formId values remain unchanged. Tests cover both ID paths, and a patch changeset documents the update.

      Changes

      Solid form ID generation

      Layer / File(s)Summary
      Generate and pass fallback form IDs
      packages/solid-form/src/createForm.tsx
      createForm generates a fallback ID with createUniqueId when no formId is configured and passes the selected ID to FormApi.
      Validate form IDs and record the patch release
      packages/solid-form/tests/createFormId.test.tsx, .changeset/great-pugs-shave.md
      Tests verify explicit IDs and the default cl-<n> format. The changeset documents the SSR-safe ID behavior.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Possibly related PRs

      • TanStack/form#2259: Both PRs add SSR-safe default formId generation for framework-specific form initialization.
      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly and concisely describes the main change: generating an SSR-safe default formId for Solid Form.
      Description check✅ PassedThe description clearly explains the change, motivation, test plan, and SSR test limitation, but omits the template's Checklist and Release Impact sections.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. 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.md
      • packages/solid-form/src/createForm.tsx
      • packages/solid-form/tests/createFormId.test.tsx
      OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)
    3. Good catch — corrected in c3d1e401. Explicit formId values 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 given passes both before and after the fix, so the explicit path was never affected.

    4. View your CI Pipeline Execution ↗ for commit c3d1e40157c96b84f52e78ef7fb9f727ba52eead

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 28sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded8sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-08-08 22:07:30 UTC

    5. More templates

      @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@2263

      commit: c3d1e40

    6. crutchcorn(GitHub profile, opens in a new tab) approved these changes

    7. :warning: Please install the 'codecov app svg image' 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.