Skip to content

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

Draft
swushi wants to merge 1 commit intoTanStack:mainfrom
swushi:fix/form-options-reactivity
Draft

fix(react-form): Make form.options reactive by adding getter#2044
swushi wants to merge 1 commit intoTanStack:mainfrom
swushi:fix/form-options-reactivity

Conversation

@swushi
Copy link

@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

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
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.

1 participant