Skip to content

feat(FieldApi): allow debounce of onChange and onBlur listener #1375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 15, 2025

Conversation

Pascalmh
Copy link
Contributor

@Pascalmh Pascalmh commented Apr 4, 2025

This allows you to listen to a change/blur event of a Field after a denounce you can set in millisecond.

It makes situations possible where you want to introduce a side effect after the user stopped typing or left the field for some time.

Copy link

nx-cloud bot commented Apr 4, 2025

View your CI Pipeline Execution ↗ for commit aeb1e38.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 15s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 20s View ↗

☁️ Nx Cloud last updated this comment at 2025-04-10 09:06:59 UTC

Copy link

pkg-pr-new bot commented Apr 4, 2025

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1375

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1375

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1375

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1375

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1375

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1375

commit: aeb1e38

@LeCarbonator
Copy link
Contributor

The naming between the debounce properties seems inconsistent. onChangeDebounceMs vs. onBlurAsyncDebounceMs.
Since the debounce should ignore async vs. sync, the blur should be renamed to onBlurDebounceMs.

@Pascalmh Pascalmh force-pushed the listeners-onChangeDebounceMs branch from 1b0a30c to 2d76c2f Compare April 7, 2025 06:27
Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.04%. Comparing base (afdaad3) to head (aeb1e38).
Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
packages/form-core/src/FieldApi.ts 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1375      +/-   ##
==========================================
+ Coverage   88.88%   89.04%   +0.16%     
==========================================
  Files          28       28              
  Lines        1277     1296      +19     
  Branches      335      340       +5     
==========================================
+ Hits         1135     1154      +19     
  Misses        126      126              
  Partials       16       16              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@Balastrong Balastrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you're using the existing timeoutIds but isn't that dangerous?

I mean, wouldn't it break if you have both a debounce on the validator and on the listener since they're sharing the same timeoutId?

@Pascalmh
Copy link
Contributor Author

wouldn't it break if you have both a debounce on the validator and on the listener since they're sharing the same timeoutId?

Good catch - I've separated the validation and listener timeoutIds

@Pascalmh Pascalmh requested a review from Balastrong April 10, 2025 06:20
Copy link
Member

@Balastrong Balastrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, also thanks for adding the docs!

@Balastrong Balastrong merged commit 008b1d4 into TanStack:main Apr 15, 2025
6 checks passed
@Pascalmh Pascalmh deleted the listeners-onChangeDebounceMs branch April 15, 2025 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants