Skip to content

Conversation

@hamed-zeidabadi
Copy link

@hamed-zeidabadi hamed-zeidabadi commented Nov 7, 2025

Add optional chaining operator (?.) when accessing nested object properties in the orderArrayBy function. This prevents TypeError when encountering null or undefined values in the object chain.

Without this fix, accessing nested properties like 'user.profile.name' would crash if 'user' or 'profile' is null/undefined.

Changes:

  • obj[i] -> obj?.[i] in reduce function for keyA
  • obj[i] -> obj?.[i] in reduce function for keyB

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

References


Note

Use optional chaining when resolving nested sort keys and push null/undefined values to the end during sorting.

  • Utilities
    • packages/utils/src/array.ts:
      • Update orderArrayBy to resolve nested keys with obj?.[i] to avoid crashes on null/undefined.
      • Adjust comparator to push null/undefined values to the end while preserving ascending/descending logic.

Written by Cursor Bugbot for commit 76df866. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Safer handling of nested keys during array sorting to avoid errors when intermediate values are missing.
    • Entries with undefined or null sort keys are now placed at the end of sorted results for more predictable ordering.

Add optional chaining operator (?.) when accessing nested object properties
in the orderArrayBy function. This prevents TypeError when encountering
null or undefined values in the object chain.

Without this fix, accessing nested properties like 'user.profile.name'
would crash if 'user' or 'profile' is null/undefined.

Changes:
- obj[i] -> obj?.[i] in reduce function for keyA
- obj[i] -> obj?.[i] in reduce function for keyB
@CLAassistant
Copy link

CLAassistant commented Nov 7, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

orderArrayBy in array utilities now uses optional chaining (obj?.[i]) to extract nested keys and treats undefined/null key values by placing those entries at the end of the sorted result.

Changes

Cohort / File(s) Change Summary
Array utilities safety & null handling
packages/utils/src/array.ts
orderArrayBy now uses optional chaining (obj?.[i]) for nested key extraction and updates sort behavior to push entries with undefined or null key values to the end of the sorted array. Public signatures unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify optional chaining yields intended undefined behavior for missing nested keys
  • Confirm sort comparison treats undefined/null consistently and places those items last
  • Check behavior across typical environments (Node/browser) and edge cases with mixed present/missing paths

Poem

🐰
Hops through keys now soft and light,
Optional chains keep errors light,
Nulls and undefined tucked to the end,
Sorting hums on, my work's well-spent,
Thump-thump — a safe, neat little mend. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding optional chaining to the orderArrayBy function to prevent crashes from null/undefined values.
Description check ✅ Passed The description includes a clear explanation of the problem, the specific changes made, and the Type of Change checkbox is properly filled (Bug fix). However, Test Scenarios and References sections are empty placeholders.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0381f7 and 76df866.

📒 Files selected for processing (1)
  • packages/utils/src/array.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/utils/src/array.ts

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

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

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.

2 participants