Skip to content

Desktop: new sessions appear at bottom because sidebar order is auto-persisted on startup #42516

@chatpongs

Description

@chatpongs

Bug

In Hermes Desktop, new sessions always appear at the bottom of the sidebar instead of at the top.

Expected behavior

When no manual sidebar ordering has been set by the user, sessions should use the natural recency order, with the newest / most recently active session at the top.

Actual behavior

On app startup, Desktop creates/persists localStorage["hermes.desktop.sessionOrder"] from the currently loaded session list.

After that, any newly created session ID is not in the persisted order list, so it gets appended to the bottom of the sidebar.

Clearing hermes.desktop.sessionOrder does not permanently fix it, because the app recreates the key on startup.

Reproduction steps

  1. Open Hermes Desktop.

  2. In DevTools Console, run:

    localStorage.removeItem('hermes.desktop.sessionOrder')
    location.reload()
  3. After reload, check localStorage again:

    localStorage.getItem('hermes.desktop.sessionOrder')
  4. The key has been recreated even though the user did not manually reorder sessions.

  5. Create a new session.

  6. The new session appears at the bottom of the Sessions list instead of the top.

Suspected cause

This appears to come from:

function reconcileOrderIds(currentIds: string[], orderIds: string[]): string[] {
  if (!currentIds.length) {
    return []
  }

  if (!orderIds.length) {
    return currentIds
  }

When orderIds is empty/missing, returning currentIds causes the current natural order to be persisted as a manual order.

Then future unknown session IDs are appended after the persisted list.

Suggested fix

Do not seed a manual order when no manual order exists.

For example:

if (!orderIds.length) {
  return []
}

or otherwise only persist hermes.desktop.sessionOrder after an actual drag/reorder action.

I tested this locally by changing that branch to return [], rebuilding Desktop, clearing hermes.desktop.sessionOrder once, and new sessions returned to appearing at the top.

Related commits

This likely started around:

  • 3fc67b733Persist desktop sidebar drag order
  • 694adec63Smooth desktop sidebar drag sorting

The specific auto-seeding behavior appears to come from 694adec63.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions