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

Merged
AV
3mo ago
+28-4

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.

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.