Skip to content

fix(form-core): Fix setBy/getBy not handling arrays properly#1517

Merged
Balastrong merged 2 commits intoTanStack:mainfrom
LeCarbonator:fix-setby-2d-array
May 22, 2025
Merged

fix(form-core): Fix setBy/getBy not handling arrays properly#1517
Balastrong merged 2 commits intoTanStack:mainfrom
LeCarbonator:fix-setby-2d-array

Conversation

@LeCarbonator
Copy link
Copy Markdown
Contributor

@LeCarbonator LeCarbonator commented May 18, 2025

Closes #1488

During parsing of the field name, multi-dimensional arrays (or names starting with an array access) were wrongly parsed in functions using makePathArray internally.

The side effects of this are listed in the linked issue, but to summarize, it wrongly interpreted array access as an object key, and that apparently lead to JavaScript silently converting the array into an object (classic ...)

The reason were mostly the regular expressions used to parse the field name, so test cases have been added and the function has been refactored.

Before

makePathArray('field[0][1].value') 
// == ['field', 0, '1', 'value']

With PR

makePathArray('field[0][1].value') 
// == ['field', 0, 1, 'value']

There is now a lookahead used to avoid mismatches with subsequent numbers. Benchmarks didn't show a significant drop in performance, but let me know if you notice something suspicious.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 18, 2025

View your CI Pipeline Execution ↗ for commit a4d992a.

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

☁️ Nx Cloud last updated this comment at 2025-05-20 05:34:39 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 18, 2025

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/lit-form

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

@tanstack/react-form

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

@tanstack/solid-form

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

@tanstack/svelte-form

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

@tanstack/vue-form

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

commit: a4d992a

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.13%. Comparing base (f13c4ec) to head (a4d992a).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1517   +/-   ##
=======================================
  Coverage   89.13%   89.13%           
=======================================
  Files          31       31           
  Lines        1417     1417           
  Branches      362      362           
=======================================
  Hits         1263     1263           
  Misses        137      137           
  Partials       17       17           

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

@LeCarbonator LeCarbonator changed the title Fix(form-core): Fix setBy/getBy not handling arrays properly fix(form-core): Fix setBy/getBy not handling arrays properly May 18, 2025
@bompi88
Copy link
Copy Markdown

bompi88 commented May 22, 2025

LGTM 🚀

@Balastrong Balastrong merged commit 8e4f9b8 into TanStack:main May 22, 2025
6 checks passed
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.

Setting property of object in nested 2D array changes the nested array to object

3 participants