TanStack / form

🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Lit Form and Vue Form.
https://tanstack.com/form
MIT License
3.74k stars 338 forks source link

`form.update` overwrites options instead of merging #875

Closed LouisHaftmann closed 3 months ago

LouisHaftmann commented 3 months ago

Describe the bug

When calling .update(newOpts) on a FormApi instance, the form options are overwritten instead of merged.

Example:

const form = new FormApi({
  asyncDebounceMs: 5000,
});

// prints `{ asyncDebounceMs: 5000 }`
console.log(form.options);

form.update({
  defaultValues: {
    test: '',
  },
});

// prints `{ defaultValues: { test: '' } }`
console.log(form.options);

Your minimal, reproducible example

https://stackblitz.com/edit/stackblitz-starters-hvxmtx?file=index.ts

Steps to reproduce

  1. Call form.update(newOpts)

Expected behavior

I would expect the options to get merged instead of overwritten

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

TanStack Form adapter

None

TanStack Form version

v0.26.4

TypeScript version

No response

Additional context

This line is the cause of this bug: https://github.com/TanStack/form/blob/bde3b1cb3de955b47034f0bfaa43dec13c67999a/packages/form-core/src/FormApi.ts#L471

crutchcorn commented 3 months ago

This is correct behavior. You can merge options yourself using {...this.field.options, other: someVal}