fix: use ?? instead of || in localeCompare fallback#950
fix: use ?? instead of || in localeCompare fallback#950hobostay wants to merge 1 commit intopingdotgg:mainfrom
Conversation
localeCompare returns 0, -1, or 1, not a boolean. Using || would fall through to the id comparison even when dates were different. Changed to ?? for correct short-circuit behavior.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
🔴 Critical
Issue on line in apps/web/src/session-logic.ts:367:
The sort comparator uses ?? to fall back to id comparison, but localeCompare returns 0 when strings are equal — not null or undefined. The expression 0 ?? left.id.localeCompare(right.id) evaluates to 0 instead of the ID comparison, breaking the tie-breaker and producing non-deterministic ordering when multiple plans share the same updatedAt. Consider restoring || so 0 triggers the secondary sort key.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/web/src/session-logic.ts around line 367:
The sort comparator uses `??` to fall back to `id` comparison, but `localeCompare` returns `0` when strings are equal — not `null` or `undefined`. The expression `0 ?? left.id.localeCompare(right.id)` evaluates to `0` instead of the ID comparison, breaking the tie-breaker and producing non-deterministic ordering when multiple plans share the same `updatedAt`. Consider restoring `||` so `0` triggers the secondary sort key.
Evidence trail:
apps/web/src/session-logic.ts lines 375-377 and 391-393 (at REVIEWED_COMMIT) show the sort comparator using `??` operator: `left.updatedAt.localeCompare(right.updatedAt) ?? left.id.localeCompare(right.id)`. JavaScript specification confirms `??` only falls back on null/undefined, and `localeCompare` returns 0 for equal strings (not null/undefined).
Summary
Fix incorrect short-circuit behavior in plan sorting logic.
Changes
session-logic.ts: Use??instead of||in localeCompare fallbackBug Details
localeComparereturns 0, -1, or 1, not a boolean. Using||would fallthrough to the id comparison even when dates were different. Changed to
??for correct short-circuit behavior.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Note
Fix
localeComparefallback infindLatestProposedPlanto use??instead of||In session-logic.ts, the sort comparator used
||to fall back toidcomparison whenupdatedAtvalues are equal. SincelocaleComparereturns0(falsy) for equal strings,||correctly triggered the fallback — but||also triggers on any falsy value, making the intent unclear. Replacing with??makes the nullish-only intent explicit and matches standard comparator chaining. Risk:??only falls back onnull/undefined, not0, so iflocaleCompareever returns a non-zero falsy value the fallback no longer triggers — though in practicelocaleComparereturns integers, so behavior is unchanged.📊 Macroscope summarized 8c8f1a0. 1 file reviewed, 2 issues evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues