@tanstack/form-core 1.28.0 → 1.28.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,7 +33,6 @@ class FormApi {
33
33
  constructor(opts) {
34
34
  this.options = {};
35
35
  this.fieldInfo = {};
36
- this.prevTransformArray = [];
37
36
  this.mount = () => {
38
37
  const cleanupFieldMetaDerived = this.fieldMetaDerived.mount();
39
38
  const cleanupStoreDerived = this.store.mount();
@@ -96,12 +95,9 @@ class FormApi {
96
95
  if (!options) return;
97
96
  const oldOptions = this.options;
98
97
  this.options = options;
99
- const shouldUpdateReeval = !!options.transform?.deps?.some(
100
- (val, i) => val !== this.prevTransformArray[i]
101
- );
102
98
  const shouldUpdateValues = options.defaultValues && !utils.evaluate(options.defaultValues, oldOptions.defaultValues) && !this.state.isTouched;
103
99
  const shouldUpdateState = !utils.evaluate(options.defaultState, oldOptions.defaultState) && !this.state.isTouched;
104
- if (!shouldUpdateValues && !shouldUpdateState && !shouldUpdateReeval) return;
100
+ if (!shouldUpdateValues && !shouldUpdateState) return;
105
101
  store.batch(() => {
106
102
  this.baseStore.setState(
107
103
  () => getDefaultFormState(
@@ -111,8 +107,7 @@ class FormApi {
111
107
  shouldUpdateState ? options.defaultState : {},
112
108
  shouldUpdateValues ? {
113
109
  values: options.defaultValues
114
- } : {},
115
- shouldUpdateReeval ? { _force_re_eval: !this.state._force_re_eval } : {}
110
+ } : {}
116
111
  )
117
112
  )
118
113
  );
@@ -866,12 +861,42 @@ class FormApi {
866
861
  };
867
862
  this._formId = opts?.formId ?? utils.uuid();
868
863
  this._devtoolsSubmissionOverride = false;
869
- this.baseStore = new store.Store(
870
- getDefaultFormState({
871
- ...opts?.defaultState,
872
- values: opts?.defaultValues ?? opts?.defaultState?.values
873
- })
874
- );
864
+ let baseStoreVal = getDefaultFormState({
865
+ ...opts?.defaultState,
866
+ values: opts?.defaultValues ?? opts?.defaultState?.values
867
+ });
868
+ if (opts?.transform) {
869
+ baseStoreVal = opts.transform({ state: baseStoreVal }).state;
870
+ for (const errKey of Object.keys(baseStoreVal.errorMap)) {
871
+ const errKeyMap = baseStoreVal.errorMap[errKey];
872
+ if (errKeyMap === void 0 || !utils.isGlobalFormValidationError(errKeyMap)) {
873
+ continue;
874
+ }
875
+ for (const fieldName of Object.keys(errKeyMap.fields)) {
876
+ const fieldErr = errKeyMap.fields[fieldName];
877
+ if (fieldErr === void 0) {
878
+ continue;
879
+ }
880
+ const existingFieldMeta = baseStoreVal.fieldMetaBase[fieldName];
881
+ baseStoreVal.fieldMetaBase[fieldName] = {
882
+ isTouched: false,
883
+ isValidating: false,
884
+ isBlurred: false,
885
+ isDirty: false,
886
+ ...existingFieldMeta ?? {},
887
+ errorSourceMap: {
888
+ ...existingFieldMeta?.["errorSourceMap"] ?? {},
889
+ onChange: "form"
890
+ },
891
+ errorMap: {
892
+ ...existingFieldMeta?.["errorMap"] ?? {},
893
+ [errKey]: fieldErr
894
+ }
895
+ };
896
+ }
897
+ }
898
+ }
899
+ this.baseStore = new store.Store(baseStoreVal);
875
900
  this.fieldMetaDerived = new store.Derived({
876
901
  deps: [this.baseStore],
877
902
  fn: ({ prevDepVals, currDepVals, prevVal: _prevVal }) => {
@@ -984,7 +1009,7 @@ class FormApi {
984
1009
  if (prevVal && prevBaseStore && prevVal.errorMap === errorMap && prevVal.fieldMeta === this.fieldMetaDerived.state && prevVal.errors === errors && prevVal.isFieldsValidating === isFieldsValidating && prevVal.isFieldsValid === isFieldsValid && prevVal.isFormValid === isFormValid && prevVal.isValid === isValid && prevVal.canSubmit === canSubmit && prevVal.isTouched === isTouched && prevVal.isBlurred === isBlurred && prevVal.isPristine === isPristine && prevVal.isDefaultValue === isDefaultValue && prevVal.isDirty === isDirty && utils.evaluate(prevBaseStore, currBaseStore)) {
985
1010
  return prevVal;
986
1011
  }
987
- let state = {
1012
+ const state = {
988
1013
  ...currBaseStore,
989
1014
  errorMap,
990
1015
  fieldMeta: this.fieldMetaDerived.state,
@@ -1000,14 +1025,6 @@ class FormApi {
1000
1025
  isDefaultValue,
1001
1026
  isDirty
1002
1027
  };
1003
- const transformArray = this.options.transform?.deps ?? [];
1004
- const shouldTransform = transformArray.length !== this.prevTransformArray.length || transformArray.some((val, i) => val !== this.prevTransformArray[i]);
1005
- if (shouldTransform) {
1006
- const newObj = Object.assign({}, this, { state });
1007
- this.options.transform?.fn(newObj);
1008
- state = newObj.state;
1009
- this.prevTransformArray = transformArray;
1010
- }
1011
1028
  return state;
1012
1029
  }
1013
1030
  });