diff --git a/.changeset/sparkly-paths-sort.md b/.changeset/sparkly-paths-sort.md new file mode 100644 index 000000000..bd47578b3 --- /dev/null +++ b/.changeset/sparkly-paths-sort.md @@ -0,0 +1,5 @@ +--- +'@tanstack/form-core': patch +--- + +Bump TanStack pacer to pacer-lite for reduced custom event emissions. diff --git a/packages/form-core/package.json b/packages/form-core/package.json index 898c25e38..a6db884f3 100644 --- a/packages/form-core/package.json +++ b/packages/form-core/package.json @@ -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": { diff --git a/packages/form-core/src/FormApi.ts b/packages/form-core/src/FormApi.ts index 319b98531..2247e0590 100644 --- a/packages/form-core/src/FormApi.ts +++ b/packages/form-core/src/FormApi.ts @@ -1,5 +1,4 @@ import { Derived, Store, batch } from '@tanstack/store' -import { throttle } from '@tanstack/pacer' import { deleteBy, determineFormLevelErrorSourceAndValue, @@ -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, @@ -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 diff --git a/packages/form-core/src/utils.ts b/packages/form-core/src/utils.ts index cf9383d84..788c7c14b 100644 --- a/packages/form-core/src/utils.ts +++ b/packages/form-core/src/utils.ts @@ -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, @@ -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, + }, +) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6236d8c4e..2f30b1fee 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1233,9 +1233,9 @@ importers: '@tanstack/devtools-event-client': specifier: ^0.3.5 version: 0.3.5 - '@tanstack/pacer': - specifier: ^0.15.3 - version: 0.15.4 + '@tanstack/pacer-lite': + specifier: ^0.1.1 + version: 0.1.1 '@tanstack/store': specifier: ^0.7.7 version: 0.7.7 @@ -4791,8 +4791,8 @@ packages: resolution: {integrity: sha512-B7+x7eP2FFvi3fgd3rNH9o/Eixt+pp0zCIdGhnQbAJjFrlwIKGjGnwyJjhWJ5fMQlGks/E2LdDTqEV4W9Plx7g==} engines: {node: '>=12'} - '@tanstack/pacer@0.15.4': - resolution: {integrity: sha512-vGY+CWsFZeac3dELgB6UZ4c7OacwsLb8hvL2gLS6hTgy8Fl0Bm/aLokHaeDIP+q9F9HUZTnp360z9uv78eg8pg==} + '@tanstack/pacer-lite@0.1.1': + resolution: {integrity: sha512-y/xtNPNt/YeyoVxE/JCx+T7yjEzpezmbb+toK8DDD1P4m7Kzs5YR956+7OKexG3f8aXgC3rLZl7b1V+yNUSy5w==} engines: {node: '>=18'} '@tanstack/query-core@5.90.5': @@ -14259,10 +14259,7 @@ snapshots: '@tanstack/history@1.133.28': {} - '@tanstack/pacer@0.15.4': - dependencies: - '@tanstack/devtools-event-client': 0.3.5 - '@tanstack/store': 0.7.7 + '@tanstack/pacer-lite@0.1.1': {} '@tanstack/query-core@5.90.5': {}