Skip to content

feat(form-core): make path optimization#2119

Open
harry-whorlow wants to merge 1 commit intomainfrom
make-path
Open

feat(form-core): make path optimization#2119
harry-whorlow wants to merge 1 commit intomainfrom
make-path

Conversation

@harry-whorlow
Copy link
Copy Markdown
Contributor

@harry-whorlow harry-whorlow commented Apr 10, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Optimized form field path parsing for improved reliability with complex path formats involving dots, brackets, and numeric segments.

@harry-whorlow
Copy link
Copy Markdown
Contributor Author

Screenshot 2026-04-10 at 22 21 55

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

This PR adds a changelog entry and optimizes the makePathArray utility function by replacing complex regex-based numeric segment parsing with a streamlined transformation pipeline that handles bracket notation conversion, dot collapsing, and integer parsing.

Changes

Cohort / File(s) Summary
Changeset Declaration
.changeset/olive-cloths-beam.md
Declares a patch-level release for @tanstack/form-core documenting the makePathArray optimization.
Path Parsing Optimization
packages/form-core/src/utils.ts
Simplifies makePathArray by removing complex regex patterns and replacing with direct transformations: bracket stripping/conversion, dot collapsing, and conditional integer parsing; reduces implementation from 36 to 10 lines.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A regex tangle we did unwind,
Simpler paths for paths unkind,
Dots and brackets dance and flow,
makePathArray steals the show,
With clarity, the codebase glows! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description provided by the author, failing to follow the required template structure with sections for Changes, Checklist, and Release Impact. Add a pull request description following the template with details about the changes, a completed checklist, and confirmation of changeset generation for this patch release.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(form-core): make path optimization' directly describes the main change: optimizing the makePathArray utility function in form-core.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch make-path

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.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 10, 2026

View your CI Pipeline Execution ↗ for commit 5100e29

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

☁️ Nx Cloud last updated this comment at 2026-04-10 20:27:39 UTC

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 12 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/form-core 1.29.0 → 1.29.1 Changeset
@tanstack/angular-form 1.29.0 → 1.29.1 Dependent
@tanstack/form-devtools 0.2.21 → 0.2.22 Dependent
@tanstack/lit-form 1.23.27 → 1.23.28 Dependent
@tanstack/react-form 1.29.0 → 1.29.1 Dependent
@tanstack/react-form-devtools 0.2.21 → 0.2.22 Dependent
@tanstack/react-form-nextjs 1.29.0 → 1.29.1 Dependent
@tanstack/react-form-remix 1.29.0 → 1.29.1 Dependent
@tanstack/react-form-start 1.29.0 → 1.29.1 Dependent
@tanstack/solid-form 1.29.0 → 1.29.1 Dependent
@tanstack/solid-form-devtools 0.2.21 → 0.2.22 Dependent
@tanstack/svelte-form 1.29.0 → 1.29.1 Dependent
@tanstack/vue-form 1.29.0 → 1.29.1 Dependent

@harry-whorlow
Copy link
Copy Markdown
Contributor Author

relates to #1545

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/form-devtools

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

@tanstack/lit-form

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

@tanstack/react-form

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

@tanstack/react-form-devtools

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

@tanstack/react-form-nextjs

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

@tanstack/react-form-remix

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

@tanstack/react-form-start

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

@tanstack/solid-form

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

@tanstack/solid-form-devtools

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

@tanstack/svelte-form

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

@tanstack/vue-form

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

commit: 5100e29

@sentry
Copy link
Copy Markdown

sentry bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.20%. Comparing base (6892ed0) to head (5100e29).
⚠️ Report is 167 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2119      +/-   ##
==========================================
- Coverage   90.35%   90.20%   -0.16%     
==========================================
  Files          38       49      +11     
  Lines        1752     2031     +279     
  Branches      444      531      +87     
==========================================
+ Hits         1583     1832     +249     
- Misses        149      179      +30     
  Partials       20       20              

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

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 the current code and only fix it if needed.

Inline comments:
In `@packages/form-core/src/utils.ts`:
- Around line 156-165: The path parser currently leaves a leading empty segment
for paths like ".child" (produced by concatenatePaths) because it doesn't strip
leading dots; update the replace chain that processes the path (the
.replace(/(^\[)|]/g, '')... sequence) to remove any leading dots before
splitting (e.g. add .replace(/^\.+/, '') or equivalent) so that ".child" becomes
"child" and downstream helpers (getBy, setBy, deleteBy) no longer treat an
empty-string key as the first segment.
🪄 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: 5c261b4a-32bc-4d4f-b0ec-4cc0e13ed797

📥 Commits

Reviewing files that changed from the base of the PR and between 254f157 and 5100e29.

📒 Files selected for processing (2)
  • .changeset/olive-cloths-beam.md
  • packages/form-core/src/utils.ts

Comment on lines +156 to +165
// Leading `[` may lead to wrong parsing (e.g. '[0][1]' → '0.1', not '.0.1')
return str
.replace(/(^\[)|]/g, '')
.replace(/\[/g, '.')
.replace(/\.{2,}/g, '.')
.split('.')
.map((segment) => {
const num = parseInt(segment, 10)
return String(num) === segment ? num : segment
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Strip leading-dot paths before splitting.

concatenatePaths can legitimately produce .child when the parent path is empty, but this parser still turns that into ['', 'child']. Downstream, getBy/setBy/deleteBy will then read or write under an empty-string key instead of child.

Suggested fix
   return str
+    .replace(/^\./, '')
     .replace(/(^\[)|]/g, '')
     .replace(/\[/g, '.')
     .replace(/\.{2,}/g, '.')
     .split('.')
+    .filter(Boolean)
     .map((segment) => {
       const num = parseInt(segment, 10)
       return String(num) === segment ? num : segment
     })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Leading `[` may lead to wrong parsing (e.g. '[0][1]' → '0.1', not '.0.1')
return str
.replace(/(^\[)|]/g, '')
.replace(/\[/g, '.')
.replace(/\.{2,}/g, '.')
.split('.')
.map((segment) => {
const num = parseInt(segment, 10)
return String(num) === segment ? num : segment
})
// Leading `[` may lead to wrong parsing (e.g. '[0][1]' → '0.1', not '.0.1')
return str
.replace(/^\./, '')
.replace(/(^\[)|]/g, '')
.replace(/\[/g, '.')
.replace(/\.{2,}/g, '.')
.split('.')
.filter(Boolean)
.map((segment) => {
const num = parseInt(segment, 10)
return String(num) === segment ? num : segment
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/form-core/src/utils.ts` around lines 156 - 165, The path parser
currently leaves a leading empty segment for paths like ".child" (produced by
concatenatePaths) because it doesn't strip leading dots; update the replace
chain that processes the path (the .replace(/(^\[)|]/g, '')... sequence) to
remove any leading dots before splitting (e.g. add .replace(/^\.+/, '') or
equivalent) so that ".child" becomes "child" and downstream helpers (getBy,
setBy, deleteBy) no longer treat an empty-string key as the first segment.

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.

1 participant