Skip to content

fix(react-form): Make form.options reactive by adding getter#2044

Draft
swushi wants to merge 3 commits into
TanStack:mainfrom
swushi:fix/form-options-reactivity
Draft

fix(react-form): Make form.options reactive by adding getter#2044
swushi wants to merge 3 commits into
TanStack:mainfrom
swushi:fix/form-options-reactivity

Conversation

@swushi
Copy link
Copy Markdown

@swushi swushi commented Feb 17, 2026

Summary

Fixes an issue where form.options.defaultValues was not reactive when initializing a form with async data.

Problem

When using useForm() with async data:

const { data } = useAsyncApiData();

const form = useForm({
  defaultValues: data ?? { foo: '' },
})

// When data loads, `form.state.values` updates correctly,
// but form.options.defaultValues is stale (i.e. `{ foo: '' }`)
const hasChanges = form.state.values.foo !== form.options.defaultValues.foo; // incorrectly true

Root Cause

The options object was captured in the useMemo closure and never updated when formApi.options changed, even though formApi.update() was called in the effect lifecycle.

Solution

Added a getter for options (similar to the existing state getter) to ensure the latest options are always returned:

get options() {
  return formApi.options
},

This follows the same pattern as the state getter, as mentioned in the existing comment: "We must add all getters from core's FormApi here, as otherwise the spread operator won't catch those"

Related Discussion

https://canary.discord.com/channels/719702312431386674/1471891391348215972

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 17, 2026

⚠️ No Changeset found

Latest commit: 29a65ed

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Fixes an issue where form.options.defaultValues was not reactive when
initializing a form with async data. The options object was captured
in the useMemo closure and never updated when formApi.options changed.

Adding a getter for options (similar to the existing state getter)
ensures that the latest options are always returned, fixing reactivity
issues when comparing current values to defaultValues.
@swushi swushi force-pushed the fix/form-options-reactivity branch from 9fc39cc to 29a65ed Compare February 17, 2026 15:12
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 2, 2026

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/form-devtools

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

@tanstack/lit-form

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

@tanstack/preact-form

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

@tanstack/react-form

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

@tanstack/react-form-devtools

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

@tanstack/react-form-nextjs

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

@tanstack/react-form-remix

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

@tanstack/react-form-start

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

@tanstack/solid-form

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

@tanstack/solid-form-devtools

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

@tanstack/svelte-form

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

@tanstack/vue-form

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

commit: 84f08fa

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 2, 2026

View your CI Pipeline Execution ↗ for commit 84f08fa

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

☁️ Nx Cloud last updated this comment at 2026-05-11 14:35:01 UTC

@sentry
Copy link
Copy Markdown

sentry Bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.20%. Comparing base (6892ed0) to head (84f08fa).
⚠️ Report is 214 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2044       +/-   ##
===========================================
- Coverage   90.35%   57.20%   -33.16%     
===========================================
  Files          38       18       -20     
  Lines        1752      250     -1502     
  Branches      444       47      -397     
===========================================
- Hits         1583      143     -1440     
+ Misses        149       92       -57     
+ Partials       20       15        -5     

☔ View full report in Codecov by Sentry.
📢 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.

@crutchcorn
Copy link
Copy Markdown
Member

@swushi this look good! Can you add a test in either form-core or react-form that validates this change? Would help us not regress in the future.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f42aea50-12ed-4021-ac6e-63d74c7323d2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

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.

3 participants