-
-
Couldn't load subscription status.
- Fork 535
fix(form-core): make fieldMeta values optional to reflect runtime behaviour. #1787
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
LeCarbonator
merged 9 commits into
TanStack:main
from
DexAsHisH:fix/fieldmeta-undefined-type
Oct 23, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2e153e3
fix(form-core): make fieldMeta values optional to reflect runtime beh…
DexAsHisH 74a9d29
chore: add changeset
DexAsHisH df8f012
ci: apply automated fixes and generate docs
autofix-ci[bot] e31a769
Merge branch 'main' into fix/fieldmeta-undefined-type
LeCarbonator e258f20
refactor: address review feedback, change to patch version and clean …
DexAsHisH 844a63c
ci: apply automated fixes and generate docs
autofix-ci[bot] 39f1bf1
fix: sort imports alphabetically
DexAsHisH 5793816
chore: remove unused eslint directives
LeCarbonator 8d0762f
Adjust changeset description
LeCarbonator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/form-core': patch | ||
| --- | ||
|
|
||
| - Make `fieldMeta` record type `Partial<>` to reflect runtime behaviour |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { FieldApi, FormApi } from '../src/index' | ||
|
|
||
| describe('fieldMeta accessing', () => { | ||
| it('should return undefined for unmounted fields', () => { | ||
| const form = new FormApi({ | ||
| defaultValues: { | ||
| name: '', | ||
| email: '', | ||
| }, | ||
| }) | ||
|
|
||
| expect(form.state.fieldMeta.name).toBeUndefined() | ||
| expect(form.state.fieldMeta.email).toBeUndefined() | ||
| }) | ||
|
|
||
| it('should have defined fieldMeta after field is mounted', () => { | ||
| const form = new FormApi({ | ||
| defaultValues: { | ||
| name: '', | ||
| }, | ||
| }) | ||
|
|
||
| const field = new FieldApi({ | ||
| form, | ||
| name: 'name', | ||
| }) | ||
|
|
||
| field.mount() | ||
|
|
||
| expect(form.state.fieldMeta.name).toBeDefined() | ||
| expect(form.state.fieldMeta.name?.isValid).toBe(true) | ||
| expect(form.state.fieldMeta.name?.isTouched).toBe(false) | ||
| expect(form.state.fieldMeta.name?.isDirty).toBe(false) | ||
| }) | ||
|
|
||
| it('should handle nested field paths', () => { | ||
| const form = new FormApi({ | ||
| defaultValues: { | ||
| user: { | ||
| profile: { | ||
| firstName: '', | ||
| lastName: '', | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| expect(form.state.fieldMeta['user.profile.firstName']).toBeUndefined() | ||
| expect(form.state.fieldMeta['user.profile.lastName']).toBeUndefined() | ||
|
|
||
| const firstNameField = new FieldApi({ | ||
| form, | ||
| name: 'user.profile.firstName', | ||
| }) | ||
|
|
||
| firstNameField.mount() | ||
|
|
||
| expect(form.state.fieldMeta['user.profile.firstName']).toBeDefined() | ||
|
|
||
| expect(form.state.fieldMeta['user.profile.lastName']).toBeUndefined() | ||
| }) | ||
|
|
||
| it('should handle array fields', () => { | ||
| const form = new FormApi({ | ||
| defaultValues: { | ||
| items: ['item1', 'item2'], | ||
| }, | ||
| }) | ||
|
|
||
| expect(form.state.fieldMeta['items[0]']).toBeUndefined() | ||
| expect(form.state.fieldMeta['items[1]']).toBeUndefined() | ||
|
|
||
| const field0 = new FieldApi({ | ||
| form, | ||
| name: 'items[0]', | ||
| }) | ||
|
|
||
| field0.mount() | ||
|
|
||
| expect(form.state.fieldMeta['items[0]']).toBeDefined() | ||
| expect(form.state.fieldMeta['items[1]']).toBeUndefined() | ||
| }) | ||
|
|
||
| it('should handle getFieldMeta returning undefined', () => { | ||
| const form = new FormApi({ | ||
| defaultValues: { | ||
| name: '', | ||
| }, | ||
| }) | ||
|
|
||
| const fieldMeta = form.getFieldMeta('name') | ||
| expect(fieldMeta).toBeUndefined() | ||
|
|
||
| const field = new FieldApi({ | ||
| form, | ||
| name: 'name', | ||
| }) | ||
|
|
||
| field.mount() | ||
|
|
||
| const fieldMetaAfterMount = form.getFieldMeta('name') | ||
| expect(fieldMetaAfterMount).toBeDefined() | ||
| expect(fieldMetaAfterMount?.isValid).toBe(true) | ||
| }) | ||
|
|
||
| it('should handle multiple fields with mixed mount states', () => { | ||
| const form = new FormApi({ | ||
| defaultValues: { | ||
| firstName: '', | ||
| lastName: '', | ||
| email: '', | ||
| }, | ||
| }) | ||
|
|
||
| const firstNameField = new FieldApi({ | ||
| form, | ||
| name: 'firstName', | ||
| }) | ||
|
|
||
| const lastNameField = new FieldApi({ | ||
| form, | ||
| name: 'lastName', | ||
| }) | ||
|
|
||
| firstNameField.mount() | ||
|
|
||
| expect(form.state.fieldMeta.firstName).toBeDefined() | ||
| expect(form.state.fieldMeta.email).toBeUndefined() | ||
| }) | ||
|
|
||
| it('should preserve fieldMeta after unmounting and remounting', () => { | ||
| const form = new FormApi({ | ||
| defaultValues: { | ||
| name: '', | ||
| }, | ||
| }) | ||
|
|
||
| const field = new FieldApi({ | ||
| form, | ||
| name: 'name', | ||
| }) | ||
|
|
||
| const cleanup = field.mount() | ||
|
|
||
| field.setValue('test') | ||
| expect(form.state.fieldMeta.name?.isTouched).toBe(true) | ||
| expect(form.state.fieldMeta.name?.isDirty).toBe(true) | ||
|
|
||
| cleanup() | ||
|
|
||
| const metaAfterCleanup = form.state.fieldMeta.name | ||
|
|
||
| expect(metaAfterCleanup).toBeDefined() | ||
| }) | ||
|
|
||
| it('should work with form validation that accesses fieldMeta', () => { | ||
| const form = new FormApi({ | ||
| defaultValues: { | ||
| password: '', | ||
| confirmPassword: '', | ||
| }, | ||
| validators: { | ||
| onChange: ({ value }) => { | ||
| if (value.password !== value.confirmPassword) { | ||
| return 'Passwords must match' | ||
| } | ||
| return undefined | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| form.mount() | ||
|
|
||
| const passwordField = new FieldApi({ | ||
| form, | ||
| name: 'password', | ||
| }) | ||
|
|
||
| passwordField.mount() | ||
|
|
||
| expect(() => { | ||
| passwordField.setValue('test123') | ||
| }).not.toThrow() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*.spec.tsfiles imply they're runtime tests, while type tests go into*.test-d.ts.fieldMeta.spec.tsdescribestring since the file tests for meta accessing and not type safety.