Skip to content

fix(desktop): make sidebar project ordering deterministic and prepend new projects - #5999

Merged
AviPeltz merged 3 commits into
mainfrom
fix-sidebar-order-tiebreak
Jul 27, 2026
Merged

AviPeltz merged 3 commits into
mainfrom
fix-sidebar-order-tiebreak

Conversation

@AviPeltz

@AviPeltz AviPeltz commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Sidebar projects were observed jumping position after reordering a workspace inside a project — an operation that never writes project order.

Root cause: the sidebar's project/section/workspace queries order by tabOrder alone, and tabOrders can collide (bulk ensure paths like the dev sidebar seeder can mint duplicates). A tie left to the query engine is broken arbitrarily, so any unrelated re-emission of the sidebar data pipeline — e.g. the flurry of local-state writes a workspace drag commits — can flip tied rows. Dragging a project self-heals the data (reorderProjects renumbers 1..n), which is why the issue is intermittent and stops reproducing after a manual project drag.

Fix

Chain a stable id as a secondary orderBy on all three queries in useDashboardSidebarData (projectId / sectionId / workspaceId). Order is now fully deterministic even with duplicate tabOrders.

Validation

  • Desktop typecheck clean, all 26 sidebar tests pass, changed file Biome-clean.
  • Persisted tabOrders inspected live via CDP during diagnosis: duplicates explain the observed jump; current values are unique, so this is preventative determinism rather than a reproducible-bug fix.

https://claude.ai/code/session_01SSUQYFamkYAjs5sDQC5RLS


Open in Stage

Summary by cubic

Fixes sidebar item jumping by making project, section, and workspace ordering deterministic. New projects now prepend to the top of the list; project rows sort in JS with a stable tiebreak so order stays correct after inserts or updates.

  • Bug Fixes

    • Projects: select tabOrder and sort rows in JS by tabOrder then projectId (fixes incremental orderBy not re-sorting; new projects no longer stick at the bottom until reload).
    • Sections/Workspaces: add secondary orderBy on sectionId/workspaceId after tabOrder in useDashboardSidebarData.
    • Prevents flicker and unexpected reordering during workspace drags or sidebar re-emits.
  • New Features

    • Projects: newly added projects now appear at the top of the sidebar (prepend tabOrder), consistent with workspace placement.

Written for commit b7a6bbe. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved dashboard sidebar ordering consistency when multiple projects, sections, or workspaces share the same tab position.
    • Ensured deterministic sidebar row ordering across updates by adding stable tie-breaks for equal tab positions.

@ghost

ghost commented Jul 27, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 3 individual chapters for you:

Title
1 Prepend new projects to the sidebar
2 Implement deterministic project sorting in JS
3 Add tie-breaking to section and workspace queries
Open in Stage

Chapters generated by Stage for commit b7a6bbe on Jul 27, 2026 10:03pm UTC.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Dashboard sidebar LiveQuery pipelines now produce deterministic project, section, and workspace ordering when tab-order values collide.

Changes

Dashboard sidebar ordering

Layer / File(s) Summary
Stable sidebar row ordering
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useDashboardSidebarData/useDashboardSidebarData.ts
Project rows are sorted in JavaScript by tabOrder and projectId; section and workspace queries add ascending identifier tie-breakers after their primary tab-order sorts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main change: deterministic sidebar ordering, including the new project-prepend behavior.
Description check ✅ Passed It covers the problem, fix, and validation, but it doesn't match the template headings exactly and omits the checklist.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-sidebar-order-tiebreak

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.

AviPeltz added 2 commits July 27, 2026 14:56
Sidebar project/section/workspace queries ordered by tabOrder alone, but
tabOrders can collide (bulk ensure paths can mint duplicates), and a tie
left to the query engine flips arbitrarily on unrelated re-emissions —
projects visibly jumped when a workspace reorder recomputed the pipeline.
Chain a stable id as the secondary orderBy on all three queries.

Claude-Session: https://claude.ai/code/session_01SSUQYFamkYAjs5sDQC5RLS
The live query's incremental orderBy does not reliably re-sort when
placement rows are inserted or renumbered — a newly added project with
tabOrder 1 stayed appended at the bottom of the sidebar until a full
reload re-materialized the query. Workspaces and sections are immune
because buildDashboardSidebarProjects re-sorts them in JS; project order
was taken straight from the query emission. Select tabOrder and sort the
rows in a memo instead (tabOrder, then projectId for duplicate-proof
determinism).

Claude-Session: https://claude.ai/code/session_01SSUQYFamkYAjs5sDQC5RLS
New workspaces already prepend to the top of their project's lane; new
projects appended to the bottom of the project list. Use the existing
prepend helper so the project you just added — the one you're about to
work in — lands first, consistent with workspace placement.

Claude-Session: https://claude.ai/code/session_01SSUQYFamkYAjs5sDQC5RLS
@AviPeltz AviPeltz changed the title fix(desktop): break sidebar ordering ties deterministically fix(desktop): make sidebar project ordering deterministic and prepend new projects Jul 27, 2026
@AviPeltz
AviPeltz merged commit 1f5cfdb into main Jul 27, 2026
11 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch

Thank you for your contribution! 🎉

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.

1 participant