Skip to content

Commit 49f52a1

Browse files
committed
Merge branch 'new-store-alien-signals' into make-go-fast
# Conflicts: # packages/form-core/package.json # packages/form-core/src/FieldApi.ts # packages/form-core/src/FormApi.ts # packages/form-core/src/transform.ts # packages/react-form/package.json # pnpm-lock.yaml
2 parents e6984aa + b134a18 commit 49f52a1

19 files changed

Lines changed: 412 additions & 1304 deletions

File tree

examples/react/next-server-actions-zod/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"@tanstack/react-form-nextjs": "^1.28.3",
12-
"@tanstack/react-store": "^0.8.1",
12+
"@tanstack/react-store": "^0.9.1",
1313
"next": "16.0.5",
1414
"react": "^19.0.0",
1515
"react-dom": "^19.0.0",

examples/react/next-server-actions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"@tanstack/react-form-nextjs": "^1.28.3",
12-
"@tanstack/react-store": "^0.8.1",
12+
"@tanstack/react-store": "^0.9.1",
1313
"next": "16.0.5",
1414
"react": "^19.0.0",
1515
"react-dom": "^19.0.0"

examples/react/remix/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@remix-run/react": "^2.17.1",
1313
"@remix-run/serve": "^2.17.1",
1414
"@tanstack/react-form-remix": "^1.28.3",
15-
"@tanstack/react-store": "^0.8.1",
15+
"@tanstack/react-store": "^0.9.1",
1616
"isbot": "^5.1.30",
1717
"react": "^19.0.0",
1818
"react-dom": "^19.0.0"

examples/react/tanstack-start/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@tanstack/react-form-start": "^1.28.3",
1515
"@tanstack/react-router": "^1.134.9",
1616
"@tanstack/react-start": "^1.134.9",
17-
"@tanstack/react-store": "^0.8.1",
17+
"@tanstack/react-store": "^0.9.1",
1818
"react": "^19.0.0",
1919
"react-dom": "^19.0.0"
2020
},

packages/angular-form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"src"
4343
],
4444
"dependencies": {
45-
"@tanstack/angular-store": "^0.8.1",
45+
"@tanstack/angular-store": "^0.9.1",
4646
"@tanstack/form-core": "workspace:*",
4747
"tslib": "^2.8.1"
4848
},

packages/form-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"dependencies": {
5454
"@tanstack/devtools-event-client": "^0.4.0",
5555
"@tanstack/pacer-lite": "^0.1.1",
56-
"@tanstack/store": "https://pkg.pr.new/@tanstack/store@265"
56+
"@tanstack/store": "^0.9.1"
5757
},
5858
"devDependencies": {
5959
"arktype": "^2.1.22",

packages/form-core/src/FieldApi.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { createStore, type Store } from '@tanstack/store'
1+
import { batch, createStore} from '@tanstack/store'
22
import {
33
isStandardSchemaValidator,
44
standardSchemaValidators,
55
} from './standardSchemaValidator'
6-
import { defaultFieldMeta } from './metaHelper'
76
import {
87
determineFieldLevelErrorSourceAndValue,
98
evaluate,
@@ -14,6 +13,7 @@ import {
1413
mergeOpts,
1514
} from './utils'
1615
import { defaultValidationLogic } from './ValidationLogic'
16+
import type {ReadonlyStore} from '@tanstack/store';
1717
import type { DeepKeys, DeepValue, UnwrapOneLevelOfArray } from './util-types'
1818
import type {
1919
StandardSchemaV1,
@@ -1091,7 +1091,7 @@ export class FieldApi<
10911091
/**
10921092
* The field state store.
10931093
*/
1094-
store!: Store<
1094+
store!: ReadonlyStore<
10951095
FieldState<
10961096
TParentData,
10971097
TName,
@@ -1709,62 +1709,62 @@ export class FieldApi<
17091709
// Needs type cast as eslint errantly believes this is always falsy
17101710
let hasErrored = false as boolean
17111711

1712-
// batch(() => {
1713-
const validateFieldFn = (
1714-
field: AnyFieldApi,
1715-
validateObj: SyncValidator<any>,
1716-
) => {
1717-
const errorMapKey = getErrorMapKey(validateObj.cause)
1712+
batch(() => {
1713+
const validateFieldFn = (
1714+
field: AnyFieldApi,
1715+
validateObj: SyncValidator<any>,
1716+
) => {
1717+
const errorMapKey = getErrorMapKey(validateObj.cause)
1718+
1719+
const fieldLevelError = validateObj.validate
1720+
? normalizeError(
1721+
field.runValidator({
1722+
validate: validateObj.validate,
1723+
value: {
1724+
value: field.store.state.value,
1725+
validationSource: 'field',
1726+
fieldApi: field,
1727+
},
1728+
type: 'validate',
1729+
}),
1730+
)
1731+
: undefined
17181732

1719-
const fieldLevelError = validateObj.validate
1720-
? normalizeError(
1721-
field.runValidator({
1722-
validate: validateObj.validate,
1723-
value: {
1724-
value: field.store.state.value,
1725-
validationSource: 'field',
1726-
fieldApi: field,
1727-
},
1728-
type: 'validate',
1729-
}),
1730-
)
1731-
: undefined
1733+
const formLevelError = errorFromForm[errorMapKey]
17321734

1733-
const formLevelError = errorFromForm[errorMapKey]
1735+
const { newErrorValue, newSource } =
1736+
determineFieldLevelErrorSourceAndValue({
1737+
formLevelError,
1738+
fieldLevelError,
1739+
})
17341740

1735-
const { newErrorValue, newSource } =
1736-
determineFieldLevelErrorSourceAndValue({
1737-
formLevelError,
1738-
fieldLevelError,
1739-
})
1741+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1742+
if (field.state.meta.errorMap?.[errorMapKey] !== newErrorValue) {
1743+
field.setMeta((prev) => ({
1744+
...prev,
1745+
errorMap: {
1746+
...prev.errorMap,
1747+
[errorMapKey]: newErrorValue,
1748+
},
1749+
errorSourceMap: {
1750+
...prev.errorSourceMap,
1751+
[errorMapKey]: newSource,
1752+
},
1753+
}))
1754+
}
1755+
if (newErrorValue) {
1756+
hasErrored = true
1757+
}
1758+
}
17401759

1741-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1742-
if (field.state.meta.errorMap?.[errorMapKey] !== newErrorValue) {
1743-
field.setMeta((prev) => ({
1744-
...prev,
1745-
errorMap: {
1746-
...prev.errorMap,
1747-
[errorMapKey]: newErrorValue,
1748-
},
1749-
errorSourceMap: {
1750-
...prev.errorSourceMap,
1751-
[errorMapKey]: newSource,
1752-
},
1753-
}))
1760+
for (const validateObj of validates) {
1761+
validateFieldFn(this, validateObj)
17541762
}
1755-
if (newErrorValue) {
1756-
hasErrored = true
1763+
for (const fieldValitateObj of linkedFieldValidates) {
1764+
if (!fieldValitateObj.validate) continue
1765+
validateFieldFn(fieldValitateObj.field, fieldValitateObj)
17571766
}
1758-
}
1759-
1760-
for (const validateObj of validates) {
1761-
validateFieldFn(this, validateObj)
1762-
}
1763-
for (const fieldValitateObj of linkedFieldValidates) {
1764-
if (!fieldValitateObj.validate) continue
1765-
validateFieldFn(fieldValitateObj.field, fieldValitateObj)
1766-
}
1767-
// })
1767+
})
17681768

17691769
/**
17701770
* when we have an error for onSubmit in the state, we want

packages/form-core/src/FieldGroupApi.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { createStore, type Store } from '@tanstack/store'
1+
import { createStore } from '@tanstack/store'
22
import { concatenatePaths, getBy, makePathArray } from './utils'
3+
import type { ReadonlyStore } from '@tanstack/store'
34
import type { Updater } from './utils'
45
import type {
56
FormApi,
@@ -225,7 +226,7 @@ export class FieldGroupApi<
225226
return newProps
226227
}
227228

228-
store: Store<FieldGroupState<TFieldGroupData>>
229+
store: ReadonlyStore<FieldGroupState<TFieldGroupData>>
229230

230231
get state() {
231232
return this.store.state
@@ -302,7 +303,9 @@ export class FieldGroupApi<
302303
*
303304
* TODO: Remove
304305
*/
305-
mount = () => {}
306+
mount = () => {
307+
return () => {}
308+
}
306309

307310
/**
308311
* Validates the children of a specified array in the form starting from a given index until the end using the correct handlers for a given validation type.

0 commit comments

Comments
 (0)