Skip to content

Conversation

DexAsHisH
Copy link

@DexAsHisH DexAsHisH commented Oct 4, 2025

Description

Fixes #1774

This PR addresses a type safety issue where fieldMeta is typed as Record<DeepKeys<TData>, AnyFieldMeta> but is initialized as an empty object, causing runtime crashes when accessing field metadata during the first render.

Changes

  • ✅ Updated FormState interface to include undefined in fieldMeta type
  • ✅ Updated internal code to safely access fieldMeta with optional chaining
  • ✅ Added unit tests to verify fieldMeta behaviour
  • ✅ Added integration tests for React adapter
  • ✅ Updated documentation to clarify when fieldMeta is available

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Breaking Changes

This is a breaking change for TypeScript users. Code that previously accessed fieldMeta without null checks will now show type errors, preventing runtime crashes.

Migration Example:

// Before
const isValid = form.state.fieldMeta.name.isValid

// After (use optional chaining)
const isValid = form.state.fieldMeta.name?.isValid

// Or (check for undefined)
const isValid = form.state.fieldMeta.name 
  ? form.state.fieldMeta.name.isValid 
  : true

…avior

fieldMeta is typed as Record<DeepKeys<TData>, AnyFieldMeta> but is
initialized as an empty object. This causes TypeScript to incorrectly
assume that accessing any valid field key will return a defined
AnyFieldMeta object, leading to runtime crashes when accessing field
metadata during the first render.

Updated the fieldMeta type to include undefined to accurately reflect
that field metadata is only available after a field has been mounted.

BREAKING CHANGE: fieldMeta values are now typed as potentially undefined.
Code that accesses fieldMeta without null checks will now show TypeScript
errors. Use optional chaining or explicit undefined checks.

Fixes TanStack#1774
Copy link

changeset-bot bot commented Oct 4, 2025

🦋 Changeset detected

Latest commit: df8f012

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@tanstack/form-core Major
@tanstack/angular-form Patch
@tanstack/form-devtools Patch
@tanstack/lit-form Patch
@tanstack/react-form Patch
@tanstack/solid-form Patch
@tanstack/svelte-form Patch
@tanstack/vue-form Patch
@tanstack/react-form-devtools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

nx-cloud bot commented Oct 5, 2025

View your CI Pipeline Execution ↗ for commit df8f012

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ⛔ Cancelled 13s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 24s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-05 12:26:42 UTC

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.

formMeta is initially undefined, but its type is missing an undefined union
1 participant