Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/react/next-server-actions-zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@tanstack/react-form-nextjs": "^1.28.3",
"@tanstack/react-store": "^0.8.1",
"@tanstack/react-store": "^0.9.1",
"next": "16.0.5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/next-server-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@tanstack/react-form-nextjs": "^1.28.3",
"@tanstack/react-store": "^0.8.1",
"@tanstack/react-store": "^0.9.1",
"next": "16.0.5",
"react": "^19.0.0",
"react-dom": "^19.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/react/remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@remix-run/react": "^2.17.1",
"@remix-run/serve": "^2.17.1",
"@tanstack/react-form-remix": "^1.28.3",
"@tanstack/react-store": "^0.8.1",
"@tanstack/react-store": "^0.9.1",
"isbot": "^5.1.30",
"react": "^19.0.0",
"react-dom": "^19.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/react/tanstack-start/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@tanstack/react-form-start": "^1.28.3",
"@tanstack/react-router": "^1.134.9",
"@tanstack/react-start": "^1.134.9",
"@tanstack/react-store": "^0.8.1",
"@tanstack/react-store": "^0.9.1",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"src"
],
"dependencies": {
"@tanstack/angular-store": "^0.8.1",
"@tanstack/angular-store": "^0.9.1",
"@tanstack/form-core": "workspace:*",
"tslib": "^2.8.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/form-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"dependencies": {
"@tanstack/devtools-event-client": "^0.4.0",
"@tanstack/pacer-lite": "^0.1.1",
"@tanstack/store": "^0.8.1"
"@tanstack/store": "^0.9.1"
},
"devDependencies": {
"arktype": "^2.1.22",
Expand Down
25 changes: 13 additions & 12 deletions packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Derived, batch } from '@tanstack/store'
import { batch, createStore } from '@tanstack/store'
import {
isStandardSchemaValidator,
standardSchemaValidators,
Expand All @@ -8,11 +8,11 @@ import {
determineFieldLevelErrorSourceAndValue,
evaluate,
getAsyncValidatorArray,
getBy,
getSyncValidatorArray,
mergeOpts,
} from './utils'
import { defaultValidationLogic } from './ValidationLogic'
import type { ReadonlyStore } from '@tanstack/store'
import type { DeepKeys, DeepValue, UnwrapOneLevelOfArray } from './util-types'
import type {
StandardSchemaV1,
Expand Down Expand Up @@ -1090,7 +1090,7 @@ export class FieldApi<
/**
* The field state store.
*/
store!: Derived<
store!: ReadonlyStore<
FieldState<
TParentData,
TName,
Expand Down Expand Up @@ -1167,10 +1167,9 @@ export class FieldApi<
formListeners: {} as Record<ListenerCause, never>,
}

this.store = new Derived({
deps: [this.form.store],
fn: ({ prevVal: _prevVal }) => {
const prevVal = _prevVal as
this.store = createStore(
(
prevVal:
| FieldState<
TParentData,
TName,
Expand All @@ -1194,7 +1193,10 @@ export class FieldApi<
TFormOnDynamic,
TFormOnDynamicAsync
>
| undefined
| undefined,
) => {
// Temp hack to subscribe to form.store
this.form.store.get()
Comment thread
crutchcorn marked this conversation as resolved.

const meta = this.form.getFieldMeta(this.name) ?? {
...defaultFieldMeta,
Expand Down Expand Up @@ -1242,7 +1244,7 @@ export class FieldApi<
TFormOnDynamicAsync
>
},
})
)
}

/**
Expand Down Expand Up @@ -1275,8 +1277,6 @@ export class FieldApi<
* Mounts the field instance to the form.
*/
mount = () => {
const cleanup = this.store.mount()

if (this.options.defaultValue !== undefined && !this.getMeta().isTouched) {
this.form.setFieldValue(this.name, this.options.defaultValue, {
dontUpdateMeta: true,
Expand Down Expand Up @@ -1322,7 +1322,8 @@ export class FieldApi<
fieldApi: this,
})

return cleanup
// TODO: Remove
return () => {}
}

/**
Expand Down
48 changes: 23 additions & 25 deletions packages/form-core/src/FieldGroupApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Derived } from '@tanstack/store'
import { createStore } from '@tanstack/store'
import { concatenatePaths, getBy, makePathArray } from './utils'
import type { ReadonlyStore } from '@tanstack/store'
import type { Updater } from './utils'
import type {
FormApi,
Expand Down Expand Up @@ -225,7 +226,7 @@ export class FieldGroupApi<
return newProps
}

store: Derived<FieldGroupState<TFieldGroupData>>
store: ReadonlyStore<FieldGroupState<TFieldGroupData>>

get state() {
return this.store.state
Expand Down Expand Up @@ -275,38 +276,35 @@ export class FieldGroupApi<
this.fieldsMap = opts.fields
}

this.store = new Derived({
deps: [this.form.store],
fn: ({ currDepVals }) => {
const currFormStore = currDepVals[0]
let values: TFieldGroupData
if (typeof this.fieldsMap === 'string') {
// all values live at that name, so we can directly fetch it
values = getBy(currFormStore.values, this.fieldsMap)
} else {
// we need to fetch the values from all places where they were mapped from
values = {} as never
const fields: Record<keyof TFieldGroupData, string> = this
.fieldsMap as never
for (const key in fields) {
values[key] = getBy(currFormStore.values, fields[key])
}
this.store = createStore(() => {
const currFormStore = this.form.store.get()
let values: TFieldGroupData
if (typeof this.fieldsMap === 'string') {
// all values live at that name, so we can directly fetch it
values = getBy(currFormStore.values, this.fieldsMap)
} else {
// we need to fetch the values from all places where they were mapped from
values = {} as never
const fields: Record<keyof TFieldGroupData, string> = this
.fieldsMap as never
for (const key in fields) {
values[key] = getBy(currFormStore.values, fields[key])
}
}

return {
values,
}
},
return {
values,
}
})
}

/**
* Mounts the field group instance to listen to value changes.
*
* TODO: Remove
*/
mount = () => {
const cleanup = this.store.mount()

return cleanup
return () => {}
}

/**
Expand Down
Loading
Loading