Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/sparkly-paths-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/form-core': patch
---

Bump TanStack pacer to pacer-lite for reduced custom event emissions.
2 changes: 1 addition & 1 deletion packages/form-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
],
"dependencies": {
"@tanstack/devtools-event-client": "^0.3.5",
"@tanstack/pacer": "^0.15.3",
"@tanstack/pacer-lite": "^0.1.1",
"@tanstack/store": "^0.7.7"
},
"devDependencies": {
Expand Down
18 changes: 4 additions & 14 deletions packages/form-core/src/FormApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Derived, Store, batch } from '@tanstack/store'
import { throttle } from '@tanstack/pacer'
import {
deleteBy,
determineFormLevelErrorSourceAndValue,
Expand All @@ -12,16 +11,18 @@ import {
isNonEmptyArray,
mergeOpts,
setBy,
throttleFormState,
uuid,
} from './utils'
import { defaultValidationLogic } from './ValidationLogic'

import {
isStandardSchemaValidator,
standardSchemaValidators,
} from './standardSchemaValidator'
import { defaultFieldMeta, metaHelper } from './metaHelper'
import { formEventClient } from './EventClient'

// types
import type { ValidationLogicFn } from './ValidationLogic'
import type {
StandardSchemaV1,
Expand Down Expand Up @@ -1310,20 +1311,9 @@ export class FormApi<

this.update(opts || {})

const debouncedDevtoolState = throttle(
(state: AnyFormState) =>
formEventClient.emit('form-state', {
id: this._formId,
state: state,
}),
{
wait: 300,
},
)

// devtool broadcasts
this.store.subscribe(() => {
debouncedDevtoolState(this.store.state)
throttleFormState(this)
})

// devtool requests
Expand Down
16 changes: 14 additions & 2 deletions packages/form-core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defaultValidationLogic } from './ValidationLogic'
import { liteThrottle } from '@tanstack/pacer-lite'
import { formEventClient } from './EventClient'
import type { ValidationLogicProps } from './ValidationLogic'
import type { FieldValidators } from './FieldApi'
import type { FormValidators } from './FormApi'
import type { AnyFormApi, FormValidators } from './FormApi'
import type {
GlobalFormValidationError,
ValidationCause,
Expand Down Expand Up @@ -603,3 +604,14 @@ export function uuid(): string {
IDX++
return out
}

export const throttleFormState = liteThrottle(
(form: AnyFormApi) =>
formEventClient.emit('form-state', {
id: form.formId,
state: form.store.state,
}),
{
wait: 300,
},
)
15 changes: 6 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading