-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: add optional chaining in orderArrayBy to prevent crashes #8080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: preview
Are you sure you want to change the base?
fix: add optional chaining in orderArrayBy to prevent crashes #8080
Conversation
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
|
Note Other AI code review bot(s) detectedCodeRabbit 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
Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. Comment |
There was a problem hiding this 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.
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:
Description
Type of Change
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.
packages/utils/src/array.ts:orderArrayByto resolve nested keys withobj?.[i]to avoid crashes onnull/undefined.null/undefinedvalues 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