Skip to content

fix: use ?? instead of || in localeCompare fallback#950

Open
hobostay wants to merge 1 commit intopingdotgg:mainfrom
hobostay:fix/session-logic-localecompare
Open

fix: use ?? instead of || in localeCompare fallback#950
hobostay wants to merge 1 commit intopingdotgg:mainfrom
hobostay:fix/session-logic-localecompare

Conversation

@hobostay
Copy link

@hobostay hobostay commented Mar 12, 2026

Summary

Fix incorrect short-circuit behavior in plan sorting logic.

Changes

  • session-logic.ts: Use ?? instead of || in localeCompare fallback

Bug Details

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.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Note

Fix localeCompare fallback in findLatestProposedPlan to use ?? instead of ||

In session-logic.ts, the sort comparator used || to fall back to id comparison when updatedAt values are equal. Since localeCompare returns 0 (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 on null/undefined, not 0, so if localeCompare ever returns a non-zero falsy value the fallback no longer triggers — though in practice localeCompare returns integers, so behavior is unchanged.

📊 Macroscope summarized 8c8f1a0. 1 file reviewed, 2 issues evaluated, 0 issues filtered, 1 comment posted

🗂️ Filtered Issues

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.
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: feefecac-08dd-4eee-8257-e1308f9f3343

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@github-actions github-actions bot added the vouch:unvouched PR author is not yet trusted in the VOUCHED list. label Mar 12, 2026
Copy link

Choose a reason for hiding this comment

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

🔴 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant