Skip to content

Commit f88faaf

Browse files
Move to Alien-Signals Based Store (#2035)
* chore: naive migrate to new store package * chore: pass all core tests * chore: migrate React Form as well * ci: apply automated fixes and generate docs * chore: fix various other issues * chore: add changeset --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent cb2ad34 commit f88faaf

File tree

22 files changed

+312
-259
lines changed

22 files changed

+312
-259
lines changed

.changeset/silly-swans-take.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@tanstack/angular-form': patch
3+
'@tanstack/svelte-form': patch
4+
'@tanstack/react-form': patch
5+
'@tanstack/solid-form': patch
6+
'@tanstack/form-core': patch
7+
'@tanstack/lit-form': patch
8+
'@tanstack/vue-form': patch
9+
---
10+
11+
Refactor internals for substancially faster performance

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": "^0.8.1"
56+
"@tanstack/store": "^0.9.1"
5757
},
5858
"devDependencies": {
5959
"arktype": "^2.1.22",

packages/form-core/src/FieldApi.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Derived, batch } from '@tanstack/store'
1+
import { batch, createStore } from '@tanstack/store'
22
import {
33
isStandardSchemaValidator,
44
standardSchemaValidators,
@@ -8,11 +8,11 @@ import {
88
determineFieldLevelErrorSourceAndValue,
99
evaluate,
1010
getAsyncValidatorArray,
11-
getBy,
1211
getSyncValidatorArray,
1312
mergeOpts,
1413
} from './utils'
1514
import { defaultValidationLogic } from './ValidationLogic'
15+
import type { ReadonlyStore } from '@tanstack/store'
1616
import type { DeepKeys, DeepValue, UnwrapOneLevelOfArray } from './util-types'
1717
import type {
1818
StandardSchemaV1,
@@ -1090,7 +1090,7 @@ export class FieldApi<
10901090
/**
10911091
* The field state store.
10921092
*/
1093-
store!: Derived<
1093+
store!: ReadonlyStore<
10941094
FieldState<
10951095
TParentData,
10961096
TName,
@@ -1167,10 +1167,9 @@ export class FieldApi<
11671167
formListeners: {} as Record<ListenerCause, never>,
11681168
}
11691169

1170-
this.store = new Derived({
1171-
deps: [this.form.store],
1172-
fn: ({ prevVal: _prevVal }) => {
1173-
const prevVal = _prevVal as
1170+
this.store = createStore(
1171+
(
1172+
prevVal:
11741173
| FieldState<
11751174
TParentData,
11761175
TName,
@@ -1194,7 +1193,10 @@ export class FieldApi<
11941193
TFormOnDynamic,
11951194
TFormOnDynamicAsync
11961195
>
1197-
| undefined
1196+
| undefined,
1197+
) => {
1198+
// Temp hack to subscribe to form.store
1199+
this.form.store.get()
11981200

11991201
const meta = this.form.getFieldMeta(this.name) ?? {
12001202
...defaultFieldMeta,
@@ -1242,7 +1244,7 @@ export class FieldApi<
12421244
TFormOnDynamicAsync
12431245
>
12441246
},
1245-
})
1247+
)
12461248
}
12471249

12481250
/**
@@ -1275,8 +1277,6 @@ export class FieldApi<
12751277
* Mounts the field instance to the form.
12761278
*/
12771279
mount = () => {
1278-
const cleanup = this.store.mount()
1279-
12801280
if (this.options.defaultValue !== undefined && !this.getMeta().isTouched) {
12811281
this.form.setFieldValue(this.name, this.options.defaultValue, {
12821282
dontUpdateMeta: true,
@@ -1322,7 +1322,8 @@ export class FieldApi<
13221322
fieldApi: this,
13231323
})
13241324

1325-
return cleanup
1325+
// TODO: Remove
1326+
return () => {}
13261327
}
13271328

13281329
/**

packages/form-core/src/FieldGroupApi.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Derived } 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: Derived<FieldGroupState<TFieldGroupData>>
229+
store: ReadonlyStore<FieldGroupState<TFieldGroupData>>
229230

230231
get state() {
231232
return this.store.state
@@ -275,38 +276,35 @@ export class FieldGroupApi<
275276
this.fieldsMap = opts.fields
276277
}
277278

278-
this.store = new Derived({
279-
deps: [this.form.store],
280-
fn: ({ currDepVals }) => {
281-
const currFormStore = currDepVals[0]
282-
let values: TFieldGroupData
283-
if (typeof this.fieldsMap === 'string') {
284-
// all values live at that name, so we can directly fetch it
285-
values = getBy(currFormStore.values, this.fieldsMap)
286-
} else {
287-
// we need to fetch the values from all places where they were mapped from
288-
values = {} as never
289-
const fields: Record<keyof TFieldGroupData, string> = this
290-
.fieldsMap as never
291-
for (const key in fields) {
292-
values[key] = getBy(currFormStore.values, fields[key])
293-
}
279+
this.store = createStore(() => {
280+
const currFormStore = this.form.store.get()
281+
let values: TFieldGroupData
282+
if (typeof this.fieldsMap === 'string') {
283+
// all values live at that name, so we can directly fetch it
284+
values = getBy(currFormStore.values, this.fieldsMap)
285+
} else {
286+
// we need to fetch the values from all places where they were mapped from
287+
values = {} as never
288+
const fields: Record<keyof TFieldGroupData, string> = this
289+
.fieldsMap as never
290+
for (const key in fields) {
291+
values[key] = getBy(currFormStore.values, fields[key])
294292
}
293+
}
295294

296-
return {
297-
values,
298-
}
299-
},
295+
return {
296+
values,
297+
}
300298
})
301299
}
302300

303301
/**
304302
* Mounts the field group instance to listen to value changes.
303+
*
304+
* TODO: Remove
305305
*/
306306
mount = () => {
307-
const cleanup = this.store.mount()
308-
309-
return cleanup
307+
return () => {}
310308
}
311309

312310
/**

0 commit comments

Comments
 (0)