Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): preserve prefix-matching sibling fields #2318

Mergedwanxiankai(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/2318/headmerged by LeCarbonator(GitHub profile, opens in a new tab)

🎯 Changes

  • Restrict deleteField descendant cleanup to dot- and bracket-delimited field paths.
  • Preserve values, registrations, and metadata for sibling fields that only share a string prefix.
  • Add regression coverage for object fields and nested array fields.

Fixes #2317

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed field deletion so it removes only the selected field and its true nested descendants.
    • Preserved sibling fields whose names share a prefix with the deleted field.
    • Improved handling for nested object and array field paths.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Review Change Stack

      📝 Walkthrough

      Walkthrough

      deleteField now removes only dot- or bracket-delimited descendants. Regression coverage verifies that prefix-sharing sibling fields retain their values, registrations, and metadata. A patch changeset documents the fix.

      Changes

      Field deletion boundary handling

      Layer / File(s)Summary
      Path-boundary deletion and regression coverage
      packages/form-core/src/FormApi.ts, packages/form-core/tests/FieldApi.spec.ts, .changeset/tidy-forms-keep.md
      deleteField now matches only dot- and bracket-delimited descendants. Tests verify that sibling fields such as emailVerified and priceCurrency remain registered with their values and metadata. The changeset documents the patch release.

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

      Suggested reviewers: crutchcorn, pascalmh

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly summarizes the primary fix: preserving sibling fields with shared name prefixes.
      Description check✅ PassedThe description explains the change, motivation, tests, checklist completion, release impact, and changeset.
      Linked Issues check✅ PassedThe implementation and regression tests satisfy issue #2317 by enforcing path boundaries and preserving unrelated sibling fields.
      Out of Scope Changes check✅ PassedThe changeset, implementation update, and regression tests are directly related to the linked issue and stated objectives.
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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.
    2. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit aad81e62332d836b8a7b493a4209b814fc3ed462

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded4m 31sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded41sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-08-11 07:34:49 UTC

    3. 🧹 Nitpick comments (1)
      packages/form-core/tests/FieldApi.spec.ts (1)

      3390-3395: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

      Assert that the deleted fields are removed.

      This test only checks the surviving siblings. A no-op deleteField implementation would still pass. Add assertions for the deleted fields’ values, fieldInfo, and metadata.

      Suggested assertions
             form.deleteField('email')
             form.deleteField('items[0].price')
      
      +      expect(form.getFieldValue('email')).toBeUndefined()
      +      expect(form.fieldInfo.email).toBeUndefined()
      +      expect(form.state.fieldMeta.email).toBeUndefined()
             expect(form.getFieldValue('emailVerified')).toBe(true)
             expect(form.fieldInfo.emailVerified).toBeDefined()
             expect(form.state.fieldMeta.emailVerified).toBeDefined()
      +      expect(form.getFieldValue('items[0].price')).toBeUndefined()
      +      expect(form.fieldInfo['items[0].price']).toBeUndefined()
      +      expect(form.state.fieldMeta['items[0].price']).toBeUndefined()
             expect(form.getFieldValue('items[0].priceCurrency')).toBe('USD')
      🤖 Prompt for AI Agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      In `@packages/form-core/tests/FieldApi.spec.ts` around lines 3390 - 3395, Extend
      the test around the field deletion scenario to assert that each deleted field no
      longer has a value, fieldInfo entry, or fieldMeta entry. Keep the existing
      assertions for surviving sibling fields, and verify the removed paths directly
      through getFieldValue, form.fieldInfo, and form.state.fieldMeta.
      🤖 Prompt for all review comments with AI agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      Nitpick comments:
      In `@packages/form-core/tests/FieldApi.spec.ts`:
      - Around line 3390-3395: Extend the test around the field deletion scenario to
      assert that each deleted field no longer has a value, fieldInfo entry, or
      fieldMeta entry. Keep the existing assertions for surviving sibling fields, and
      verify the removed paths directly through getFieldValue, form.fieldInfo, and
      form.state.fieldMeta.

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 9b74da01-b286-4b1f-b2e1-e69e589d867a

      📥 Commits

      Reviewing files that changed from the base of the PR and between 462926e3b77e9c0ad6a777a879ef5067b0a5dc70 and aad81e62332d836b8a7b493a4209b814fc3ed462.

      📒 Files selected for processing (3)
      • .changeset/tidy-forms-keep.md
      • packages/form-core/src/FormApi.ts
      • packages/form-core/tests/FieldApi.spec.ts
    4. More templates

      @tanstack/angular-form

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

      @tanstack/form-core

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

      @tanstack/form-devtools

      npm i https://pkg.pr.new/@tanstack/form-devtools@2318

      @tanstack/lit-form

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

      @tanstack/preact-form

      npm i https://pkg.pr.new/@tanstack/preact-form@2318

      @tanstack/react-form

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

      @tanstack/react-form-devtools

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

      @tanstack/react-form-nextjs

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

      @tanstack/react-form-remix

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

      @tanstack/react-form-start

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

      @tanstack/solid-form

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

      @tanstack/solid-form-devtools

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

      @tanstack/svelte-form

      npm i https://pkg.pr.new/@tanstack/svelte-form@2318

      @tanstack/vue-form

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

      commit: aad81e6

    5. :warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

      Codecov Report

      :white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.78%. Comparing base (6892ed0) to head (aad81e6). :warning: Report is 267 commits behind head on main. :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

      Additional details and impacted files
      @@            Coverage Diff             @@
      ##             main    #2318      +/-   ##
      ==========================================
      - Coverage   90.35%   89.78%   -0.57%     
      ==========================================
        Files          38       66      +28     
        Lines        1752     3232    +1480     
        Branches      444      812     +368     
      ==========================================
      + Hits         1583     2902    +1319     
      - Misses        149      296     +147     
      - Partials       20       34      +14     

      :umbrella: View full report in Codecov by Harness. :loudspeaker: Have feedback on the report? Share it here.

      :rocket: New features to boost your workflow:

      • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
      • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
  • Sign in to join this conversation.