fix: prevent formId reset render loop #2408
main fromrefs/pull/2408/head·opened 🎯 Changes#
Fixes #2407.
useForm (and therefore useAppForm) re-creates its FormApi when formId changes. It compared prevFormId with the raw opts.formId, but stored the resolved id (opts.formId ?? fallbackFormId). After formId changed from a string to undefined, prevFormId held the generated fallback id, so the check stayed true on every render and the hook kept setting state during render ("Too many re-renders" in React, an unbounded render loop in Preact).
prevFormId now stores the raw opts.formId, matching how it is initialized and how useField/useFormGroup track their options. Changing formId back to undefined restores the generated fallback id.
The same fix is applied to @tanstack/react-form and @tanstack/preact-form, which share this code. Each package gets a regression test for undefined → 'test' → undefined → 'test'; the Preact test caps render count so an unfixed build fails instead of hanging.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
🚀 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
- Restoring
formIdtoundefinedafter using an explicit ID now correctly restores the generated ID in React and Preact forms. - Switching between explicit and generated IDs no longer causes a render loop.
- Restoring
- 1
View your CI Pipeline Execution ↗ for commit 7f1262f0c8dde12316271810eca234bbee345e04
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 4m 49s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 17s View ↗
☁️ Nx Cloud last updated this comment at
2026-09-27 07:40:22UTCMore 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-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/form-example-vue-array
- @tanstack/form-example-vue-multi-step-wizard
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@2408@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@2408@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@2408@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@2408@tanstack/preact-form
npm i https://pkg.pr.new/@tanstack/preact-form@2408@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@2408@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@2408@tanstack/react-form-nextjs
npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2408@tanstack/react-form-remix
npm i https://pkg.pr.new/@tanstack/react-form-remix@2408@tanstack/react-form-start
npm i https://pkg.pr.new/@tanstack/react-form-start@2408@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@2408@tanstack/solid-form-devtools
npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2408@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@2408@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@2408commit:
7f1262f: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 78.36%. Comparing base (
6892ed0) to head (7f1262f). :warning: Report is 280 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 #2408 +/- ## =========================================== - Coverage 90.35% 78.36% -12.00% =========================================== Files 38 26 -12 Lines 1752 513 -1239 Branches 444 64 -380 =========================================== - Hits 1583 402 -1181 + Misses 149 97 -52 + Partials 20 14 -6: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.
dasjideepak(GitHub profile, opens in a new tab) approved these changes
I ran the new tests on this branch and against
main'suseForm.tsx.- With the fix: react-form passes 24/24 and preact-form passes 23/23.
- Without it: the new test fails in both. React throws "Too many re-renders".
Storing the raw
formIdmatches howuseStatesets it up the first time, so this looks right to me.maricastroc(GitHub profile, opens in a new tab) linked this to fix #2407
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: TanStack/form/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
2e9d9ad2-746c-44a6-b363-75152d0336e3📥 Commits
Reviewing files that changed from the base of the PR and between 555509cd941ae6ea3a2966ef3c879a322b3b383c and 7f1262f0c8dde12316271810eca234bbee345e04.
📒 Files selected for processing (5)
.changeset/quiet-ids-return.mdpackages/preact-form/src/useForm.tsxpackages/preact-form/tests/useForm.test.tsxpackages/react-form/src/useForm.tsxpackages/react-form/tests/useForm.test.tsxIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
The React and Preact
useFormhooks now track the providedformId, so changing it toundefinedrestores the generated ID. Regression tests cover these transitions in both adapters.Changes#
Form ID fallback
packages/react-form/src/useForm.tsx,packages/preact-form/src/useForm.tsx,packages/react-form/tests/useForm.test.tsx,packages/preact-form/tests/useForm.test.tsx,.changeset/quiet-ids-return.mdformIdbecomesundefined. A changeset adds patch entries for both packages.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to
7f126Removing an explicit formId restores the generated identifier, including through useAppForm. Both adapter tests cover the transitions, and no material merge risk remains.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
7f126The fix stops the render loop and restores the generated form ID. A form that changes IDs may still leave developer-tool actions attached to an older form instance. No new authorization boundary or attacker-accessible path was established.
Retained concerns
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#2407. In both@tanstack/react-formand@tanstack/preact-form,prevFormIdnow stores the rawopts?.formId. The resolvedformIdstill uses `opts?.formId ?? fallbackForm…#2407. The source changes fixuseFormstate tracking, the React and Preact tests verify the regression, and the changeset documents the patch for both affected packag…Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (1 skipped: 1 unsupported.)
✨ 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