Skip to content

fix: type serverValidate decoded values - #2332

Open
kkkhs wants to merge 1 commit into
TanStack:mainfrom
kkkhs:agent/fix-servervalidate-type-inference
Open

fix: type serverValidate decoded values#2332
kkkhs wants to merge 1 commit into
TanStack:mainfrom
kkkhs:agent/fix-servervalidate-type-inference

Conversation

@kkkhs

@kkkhs kkkhs commented Aug 13, 2026

Copy link
Copy Markdown

🎯 Changes

Fixes #1438.

createServerValidate returns the object produced by decode-formdata, but the Next.js and Remix adapter return types were inferred from the form values. That made returned values look like defaultValues/validator types even when the runtime value is still decoded form data.

This keeps the decoded values typed from decode-formdata for the public return value, and only casts them to the form type where the existing validator and ServerFormState paths require it. I added type regression tests for both adapters.

Validation run locally:

  • corepack pnpm --filter @tanstack/form-core --filter @tanstack/react-form build
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix test:types:ts54
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix test:types:ts55
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix test:types:ts56
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix test:types:ts57
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix test:types:ts58
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix test:types:ts59
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix test:eslint
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix test:lib
  • corepack pnpm --filter @tanstack/react-form-nextjs --filter @tanstack/react-form-remix build
  • corepack pnpm exec prettier --check .changeset/quiet-lamps-warn.md packages/react-form-nextjs/src/createServerValidate.ts packages/react-form-nextjs/tests/createServerValidate.test-d.ts packages/react-form-remix/src/createServerValidate.ts packages/react-form-remix/tests/createServerValidate.test-d.ts
  • PATH=/tmp/corepack-pnpm-bin:$PATH corepack pnpm test:pr

Environment notes: local Node is v22.16.0 while .nvmrc asks for 24.8.0. I used corepack pnpm for pnpm 11.21.0. The final test:pr run used a temporary PATH shim so nested package scripts also resolved pnpm 11.21.0 instead of this machine's system Rush wrapper.

AI assistance was used for this change. I reviewed the final code, tests, and PR description.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Corrected server-side form validation results in Next.js and Remix integrations.
    • Successful submissions and server validation errors now preserve decoded form values accurately.
    • Improved TypeScript typing so decoded form data and individual fields are represented correctly.
  • Tests

    • Added type coverage to verify returned form data and field types across both integrations.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e639946a-e6ab-4ff0-af79-709c1d737243

📥 Commits

Reviewing files that changed from the base of the PR and between 7b8fc1d and 7e8652e.

📒 Files selected for processing (5)
  • .changeset/quiet-lamps-warn.md
  • packages/react-form-nextjs/src/createServerValidate.ts
  • packages/react-form-nextjs/tests/createServerValidate.test-d.ts
  • packages/react-form-remix/src/createServerValidate.ts
  • packages/react-form-remix/tests/createServerValidate.test-d.ts

📝 Walkthrough

Walkthrough

createServerValidate now separates decoded form data from cast validation values in the Next.js and Remix adapters. Type tests verify that returned fields are typed as unknown, and a patch Changeset documents the correction.

Changes

Server validation type correction

Layer / File(s) Summary
Separate decoded and validation values
packages/react-form-nextjs/src/createServerValidate.ts, packages/react-form-remix/src/createServerValidate.ts, .changeset/quiet-lamps-warn.md
Both adapters pass cast values to server validation while preserving decoded values for successful returns. Server error state stores the cast validation values. The Changeset marks patch releases.
Verify decoded return types
packages/react-form-nextjs/tests/createServerValidate.test-d.ts, packages/react-form-remix/tests/createServerValidate.test-d.ts
Type tests assert that awaited results use Record<string, unknown> and that fields such as age are typed as unknown.

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

Mergeability Score: ⚪ Minimal · up to 7e865

This localized change corrects the public types returned by the Next.js and Remix server-validation adapters while preserving existing runtime behavior; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

  • TanStack/form#2308: Both PRs update createServerValidate documentation or behavior for the Next.js and Remix adapters.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix to serverValidate decoded-value types.
Description check ✅ Passed The description explains the issue, implementation, tests, release impact, and required checklist items.
Linked Issues check ✅ Passed The changes address issue #1438 by preserving decoded types in public returns and adding regression tests for both adapters.
Out of Scope Changes check ✅ Passed All changes are directly related to correcting createServerValidate type inference and documenting the published fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@kkkhs
kkkhs marked this pull request as ready for review August 13, 2026 12:39
Copilot AI lite review requested due to automatic review settings August 13, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes inaccurate type inference for createServerValidate in the Next.js and Remix adapters so the successful return value is typed as the decoded FormData output (instead of the inferred form/defaultValues type), matching runtime behavior described in #1438.

Changes:

  • Stop casting decoded values to TFormData at the point of decoding; only cast where required for validation and ServerFormState.
  • Add type regression tests in both adapters asserting serverValidate returns decoded-formdata-shaped values (Record<string, unknown>).
  • Add a changeset bumping both adapter packages with a patch release.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/react-form-nextjs/src/createServerValidate.ts Returns decoded FormData values without forcing TFormData typing; keeps cast only for validator + ServerFormState error payload.
packages/react-form-remix/src/createServerValidate.ts Same typing adjustment as Next.js adapter for decoded values vs validation-cast values.
packages/react-form-nextjs/tests/createServerValidate.test-d.ts Adds type regression test asserting decoded-values return type for serverValidate.
packages/react-form-remix/tests/createServerValidate.test-d.ts Adds equivalent type regression test for Remix adapter.
.changeset/quiet-lamps-warn.md Declares patch releases for both adapters describing the return-type fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@nx-cloud

nx-cloud Bot commented Aug 13, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 7e8652e

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 7m 27s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-13 13:05:10 UTC

@pkg-pr-new

pkg-pr-new Bot commented Aug 13, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@2332

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@2332

@tanstack/form-devtools

npm i https://pkg.pr.new/@tanstack/form-devtools@2332

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@2332

@tanstack/preact-form

npm i https://pkg.pr.new/@tanstack/preact-form@2332

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@2332

@tanstack/react-form-devtools

npm i https://pkg.pr.new/@tanstack/react-form-devtools@2332

@tanstack/react-form-nextjs

npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2332

@tanstack/react-form-remix

npm i https://pkg.pr.new/@tanstack/react-form-remix@2332

@tanstack/react-form-start

npm i https://pkg.pr.new/@tanstack/react-form-start@2332

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@2332

@tanstack/solid-form-devtools

npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2332

@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@2332

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@2332

commit: 7e8652e

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (6892ed0) to head (7e8652e).
⚠️ Report is 273 commits behind head on main.

Files with missing lines Patch % Lines
...ages/react-form-nextjs/src/createServerValidate.ts 0.00% 1 Missing and 1 partial ⚠️
...kages/react-form-remix/src/createServerValidate.ts 0.00% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #2332       +/-   ##
==========================================
- Coverage   90.35%   0.00%   -90.36%     
==========================================
  Files          38       6       -32     
  Lines        1752      48     -1704     
  Branches      444      14      -430     
==========================================
- Hits         1583       0     -1583     
+ Misses        149      40      -109     
+ Partials       20       8       -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Type inference from serverValidate is misleading

3 participants