Skip to content

fix(form-core): bump _arrayVersion when async defaultValues update array fields#2190

Merged
crutchcorn merged 6 commits into
TanStack:mainfrom
mixelburg:fix/async-array-default-values
May 26, 2026
Merged

fix(form-core): bump _arrayVersion when async defaultValues update array fields#2190
crutchcorn merged 6 commits into
TanStack:mainfrom
mixelburg:fix/async-array-default-values

Conversation

@mixelburg
Copy link
Copy Markdown

@mixelburg mixelburg commented May 21, 2026

Fixes #2178

When async defaultValues resolve and update the form, array fields rendered with mode="array" were not re-rendering. This is a regression from #2172 which changed the array field reactivity signal from Object.keys(value ?? []).length to state.meta._arrayVersion. The _arrayVersion counter is bumped on explicit mutations (push/insert/remove/swap/move) but not when defaultValues change asynchronously.

The fix: after the store update in FormApi.update(), iterate over registered fields and bump _arrayVersion for any whose current value is an array. Added a regression test.

Summary by CodeRabbit

  • Bug Fixes

    • Array-mode fields now reliably update and re-render when their values change (including when async/default values are applied), fixing stale array renders.
  • Tests

    • Added a regression test verifying array fields re-render when default values are provided after initial render.
  • Chores

    • Added a patch changeset recording the fix.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9113c641-f02e-4bf7-964e-963126b1747b

📥 Commits

Reviewing files that changed from the base of the PR and between 7ca1cbc and 9b21c73.

📒 Files selected for processing (1)
  • packages/react-form/tests/useField.test.tsx

📝 Walkthrough

Walkthrough

FormApi.update now detects array-typed field values and bumps their array metadata versions when values update. A regression test confirms async-resolved array defaultValues re-render the array field, and a changeset records a patch bump for @tanstack/form-core.

Changes

Array Field Async Value Resolution Fix

Layer / File(s) Summary
Array version bumping on value update
packages/form-core/src/FormApi.ts
FormApi.update now detects array-typed field values within fieldInfo and calls metaHelper(this).bumpArrayVersion(fieldKey) to trigger metadata updates when values change.
Regression test for async array field resolution
packages/react-form/tests/useField.test.tsx
New test renders an array field with no initial items, then re-renders with resolved async defaultValues.people containing one person, asserting the DOM list and displayed name update correctly.
Changeset metadata
.changeset/nine-beds-shout.md
Adds a changeset entry bumping @tanstack/form-core as a patch and documenting the fix for async array default values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • crutchcorn

Poem

🐰 A little bump, a gentle hop,

Arrays wake up and take their spot,
When defaults arrive from far away,
The form will show them — hip hooray!
Metadata nudged, the fields all play.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: bumping _arrayVersion when async defaultValues update array fields, directly addressing the regression in FormApi.
Description check ✅ Passed The description includes the issue reference, root cause analysis, and implementation details. However, the PR template checklist items are not checked off, and the release impact section is incomplete.
Linked Issues check ✅ Passed The PR directly addresses issue #2178 by implementing the fix: bumping _arrayVersion for array fields when async defaultValues update, and includes a regression test as expected.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the regression: FormApi.update modification, regression test addition, and changeset entry. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown
Member

@crutchcorn crutchcorn left a comment

Choose a reason for hiding this comment

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

This fix makes a lot of sense. Thanks for the PR and tests

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 26, 2026

View your CI Pipeline Execution ↗ for commit 7f33ac6

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

☁️ Nx Cloud last updated this comment at 2026-05-26 14:59:46 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 26, 2026

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/form-devtools

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

@tanstack/lit-form

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

@tanstack/preact-form

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

@tanstack/react-form

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

@tanstack/react-form-devtools

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

@tanstack/react-form-nextjs

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

@tanstack/react-form-remix

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

@tanstack/react-form-start

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

@tanstack/solid-form

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

@tanstack/solid-form-devtools

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

@tanstack/svelte-form

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

@tanstack/vue-form

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

commit: 9b21c73

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@packages/react-form/tests/useField.test.tsx`:
- Line 1546: The test fails because the <ol> element uses the wrong attribute
name `data-mtestid="list"`; update that attribute to `data-testid="list"` so the
test's calls to getByTestId('list') can find the element—search for the <ol> in
the useField.test.tsx test and replace `data-mtestid` with `data-testid` where
the list is rendered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ebbab2ab-e11a-4a15-b313-5202306a23bb

📥 Commits

Reviewing files that changed from the base of the PR and between a771a95 and 7ca1cbc.

📒 Files selected for processing (1)
  • packages/react-form/tests/useField.test.tsx

Comment thread packages/react-form/tests/useField.test.tsx Outdated
@crutchcorn crutchcorn merged commit b402d7a into TanStack:main May 26, 2026
9 of 10 checks passed
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.42%. Comparing base (6892ed0) to head (9b21c73).
⚠️ Report is 229 commits behind head on main.

Files with missing lines Patch % Lines
packages/form-core/src/FormApi.ts 80.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2190      +/-   ##
==========================================
+ Coverage   90.35%   91.42%   +1.06%     
==========================================
  Files          38       59      +21     
  Lines        1752     2343     +591     
  Branches      444      585     +141     
==========================================
+ Hits         1583     2142     +559     
- Misses        149      180      +31     
- Partials       20       21       +1     

☔ 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.

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.

Async initial array values are not set

3 participants