Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): handle null field defaults #2429

Openfenet-as(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/2429/headopened

Summary

  • Fix isDefaultValue to respect an explicit field-level defaultValue: null.
  • Update resetField to fall back to the form-level default only when the field-level default is undefined.
  • Add a regression test covering field-level null defaults, value changes, and resets.

Fixes #2427

Summary by CodeRabbit

  • Bug Fixes
    • Field-level defaultValue: null is now respected when checking whether a field has its default value and when resetting a field or form. Fields with undefined defaults continue to use the form-level default.
    1. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: c63dfb06f739682a923665b1c99108a40397f51e

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

      This PR includes changesets to release 14 packages
      NameType
      @tanstack/form-corePatch
      @tanstack/angular-formPatch
      @tanstack/form-devtoolsPatch
      @tanstack/lit-formPatch
      @tanstack/preact-formPatch
      @tanstack/react-formPatch
      @tanstack/solid-formPatch
      @tanstack/svelte-formPatch
      @tanstack/vue-formPatch
      @tanstack/react-form-devtoolsPatch
      @tanstack/solid-form-devtoolsPatch
      @tanstack/react-form-nextjsPatch
      @tanstack/react-form-remixPatch
      @tanstack/react-form-startPatch

      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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      Run configuration
      • Source mode: Auto
      • Repository: TanStack/form
      • Branch: main
      • File: .coderabbit.yaml
      • Commit: 314ea3b
      • Layers: Repository YAML
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 25f4fd20-a141-4db9-8c7e-86172ec72b62
      Commits

      Reviewing files that changed from the base of the PR and between e7169e6846c3673c8adad3cb026fae894174336b and c63dfb06f739682a923665b1c99108a40397f51e.

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      No actionable comments were generated in the recent review.

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: TanStack/form/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 07ff809e-c847-46a6-9b72-3cf2bb2cc6e0
      📥 Commits

      Reviewing files that changed from the base of the PR and between 2216fdedf0a5ff17e4ef8567e1321442639b96ca and e7169e6846c3673c8adad3cb026fae894174336b.

      📒 Files selected for processing (3)
      • .changeset/null-field-default-value.md
      • packages/form-core/src/FormApi.ts
      • packages/form-core/tests/FieldApi.spec.ts

      Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

      Walkthrough

      Field-level defaultValue: null is now used when resolving isDefaultValue and when resetField selects a value. Tests cover value changes, field reset, and form reset. A patch changeset describes the behavior.

      Changes: Field Default Resolution

      Layer / File(s)Summary
      Resolve and reset nullable field defaults
      packages/form-core/src/FormApi.ts, packages/form-core/tests/FieldApi.spec.ts, .changeset/null-field-default-value.md
      Default-status checks and resetField use a field-level null default. The tests verify the default status after value changes, field reset, and form reset. The changeset records the update.
      Priority: Low

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix · Severity of issue fixed: Low

      Merge Risk: Minimal · previous review e7169

      No actionable issue remains from this review; the change appears ready to merge after normal checks.

      Pre-merge checks | Passed 4 | Failed 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Description checkWarningThe description explains the change, motivation, regression test, and linked issue. It does not use the required Changes, Checklist, or Release Impact sections, and it omits the required checklist and…Rewrite the description using the repository template. Add the Changes, Checklist, and Release Impact sections, then mark the applicable checklist items and confirm the changeset status.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: handling null field defaults in form-core.
      Linked Issues checkPassedThe PR addresses the coding requirements in #2427. FormApi now treats a field-level defaultValue: null as the selected default and uses the form-level default only when the field default is `undef…
      Out of Scope Changes checkPassedThe changes stay within the linked issue scope. The FormApi fix implements null field-default handling, the FieldApi test verifies the regression, and the form-core changeset documents the behavio…
      Docstring CoveragePassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
      Full details: Description check

      Explanation

      The description explains the change, motivation, regression test, and linked issue. It does not use the required Changes, Checklist, or Release Impact sections, and it omits the required checklist and release-impact selections.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.