Skip to content

fix : applied nested path construction from null/empty objects in setIn - #3198

Open
tmdeveloper007 wants to merge 5 commits into
Karanjot786:mainfrom
tmdeveloper007:#3193
Open

fix : applied nested path construction from null/empty objects in setIn#3198
tmdeveloper007 wants to merge 5 commits into
Karanjot786:mainfrom
tmdeveloper007:#3193

Conversation

@tmdeveloper007

Copy link
Copy Markdown

Summary of What Has Been Done

Fixed setIn() in packages/store/src/immutable.ts to correctly construct nested paths when the source object is null or an empty object. Previously, setIn(null, ['a', 'b'], 'value') returned {} instead of { a: { b: 'value' } }, and setIn(null, ['a', 0, 'b'], 'value') returned { a: { '0': [] } } instead of { a: [{ b: 'value' }] }.

Changes Made

packages/store/src/immutable.ts

  • When obj is a plain object cloned via { ...obj } and the next key is numeric with Object.keys(clone).length === 0, replace clone with [] to ensure numeric keys create real array elements instead of string-keyed object properties.
  • For the terminal step (rest.length === 0), if clone is an array and the key is a string, convert to a plain object before assignment so the property survives JSON serialization.
  • These two changes together ensure nested paths are constructed correctly from any root value.

packages/store/src/immutable.test.ts

  • Added test: setIn from null builds nested path correctly
  • Added test: setIn from null with numeric index creates array

14 tests pass.

Impact it Made

Makes setIn correctly handle cases where state is initialized from null or where paths reference deeply nested keys that have never been set. This is a common pattern in UI state trees and Redux-style stores.

Closes #3193

**Note: Please assign this PR to the tmdeveloper007 account.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@tmdeveloper007, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 707fd761-28c6-4bd0-8fcc-d431a86d5b86

📥 Commits

Reviewing files that changed from the base of the PR and between 48f63a1 and 7ea2f94.

📒 Files selected for processing (5)
  • packages/core/src/history/CommandHistory.test.ts
  • packages/core/src/history/CommandHistory.ts
  • packages/motion/src/interpolate.ts
  • packages/store/src/immutable.test.ts
  • packages/store/src/immutable.ts
✨ 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.

@github-actions github-actions Bot added area:core @termuijs/core type:testing +10 pts. Tests. labels Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core @termuijs/core type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix : setIn should construct nested paths from null or undefined root

1 participant