Closed Bug 2039595 Opened 6 months ago Closed 4 months ago

Remember expanded/collapsed state of windows/devices in open tabs sidebar panel

Categories

(Firefox :: Sidebar, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
154 Branch
Tracking Status
firefox154 --- fixed

People

(Reporter: nsharpley, Assigned: dr.seed.lu, Mentored)

References

(Blocks 1 open bug)

Details

(Whiteboard: [fidefe-sidebar][outreachy-sidebar-2026])

Attachments

(1 external file)

By default in the open tabs panel of the revamped sidebar:

  • windows are expanded. If collapsed, remember this state upon next visit to the open tabs panel.
  • devices are collapsed. If expanded, remember this state upon next visit to the open tabs panel.
Whiteboard: [fidefe-sidebar][outreachy-sidebar-2026]
No longer depends on: sidebar-opentabs

Please I ran into a design question I would appreciate your inputs on before I proceed on this Bug.

Moz-card (the component we switched to in Bug 2041801) does not have a built-in preserve-collapse-state property.

That property is on card-container, the Firefox View component we stopped using. So I would be adding the persistence logic myself in sidebar-opentabs.mjs, which is fine.

The question is what "remember this state upon next visit" should mean.

There are three options I am considering:

(a) Same browser session only. If a user collapses Window 2, closes the sidebar, and reopens it, Window 2 is still collapsed. After a Firefox restart all windows go back to expanded.

(b) Across browser restarts, keyed by window position. We persist "Window 1's last state", "Window 2's last state" and so on as prefs. This works across restarts, but if a user closes one window and reopens, positions shift and the state might move to the wrong window.

(c) Across browser restarts, keyed by a stable window identity. This needs session-restore-stable window IDs which I would have to look into further, and may not exist.

Personally I would lean towards the first option more, considering the inner window ID is unique within a session.

Please Which would you prefer? I am fine with implementing whichever, however I need to have a clearer idea of what is required before I continue.

Thank you.

Flags: needinfo?(nsharpley)
Flags: needinfo?(kcochrane)

Nikki has reached out to UX for this and will respond soon

Flags: needinfo?(kcochrane)

(c) Across browser restarts, keyed by a stable window identity. This needs session-restore-stable window IDs which I would have to look into further, and may not exist.

SessionStore tracks a stable identifier for browser windows in window._Ssi. There's no public accessor for it, but we could add one. That would facilitate restoring state across restarts.

Thank you Sam, that pointer to window._Ssi is really helpful.

Following the direction of Kelly and Nikki on Element, we are going ahead with option (c), keyed by a stable window identity that survives restarts.

Before I start the implementation, please I would appreciate your inputs on a few things:

  1. Should the new public accessor for _Ssi be added as part of this bug, or would you prefer it as a separate dependency bug so the session-restore reviewers can handle it on its own? Whichever works for me, however I'll like to know which path will be easier for review.

  2. If it stays in this bug, do you have a preferred name and shape for the accessor? I was thinking of something like SessionStore.getCurrentSessionId(window) returning the _Ssi value, but I am fine with following whatever pattern works best.

  3. For the persisted state itself, would something like sidebar.openTabsPanel.collapsedWindows work as the pref name, storing a JSON map of _Ssi to collapsed boolean? Or is there a different shape that would fit better?

Once I get your feedbacks, I'll proceed.

Thank you.

Flags: needinfo?(sfoster)
Flags: needinfo?(kcochrane)

Let's go with SessionStore.getWindowId(window) - the session part is implicit. I don't think the change to SessionStore.sys.mjs needs to be in its own patch.

A pref called sidebar.openTabsPanel.collapsedWindows storing a JSON string of _SSi ids to booleans sounds good to me.

Note that the _SSi property is just an incrementing integer, so it may be possible to have collisions. I think you'll want to do some bookkeeping to clear out state associated with windows that no longer exist when initializing.

It gets a little complicated with closed windows. SessionStore allows you to re-open a recently-closed window, but a re-opened window gets a new_SSi. This is distinct from restoring windows that were open before the browser last quit. I think I'm going to suggest you consider preserving collapsed/expanded state across window closing/re-opening as a follow-up. I think it should be possible to keep track of a window through closing and reopening and restore the expected collapsed/expanded state but it might also be a case of diminishing returns.

Flags: needinfo?(sfoster)
Flags: needinfo?(nsharpley)
Flags: needinfo?(kcochrane)

This persists the collapsed state of each window's card in the Open Tabs
sidebar panel across browser restarts.

A new public accessor SessionStore.getWindowId(window) exposes the
existing internal _SSi identifier so the sidebar code can key per-window state.

The collapsed state is stored as a JSON map in a new
sidebar.openTabsPanel.collapsedWindows pref.

On panel mount the pref is hydrated into a Map, and a bookkeeping pass
drops any entries whose _SSi is no longer in the current set of open windows.

When the user toggles a card, the change is written through to the pref and a
CollapsedWindowsChanged event is fired on the shared openTabsTarget so
any panel in another window updates immediately.

Private windows skip the pref so collapsed state does not leak across private sessions.

Preserving collapsed state across close-and-reopen of an
individual window (which receives a new _SSi from SessionStore) is
intentionally out of scope.

I will file that as a follow-up.

Assignee: nobody → dr.seed.lu
Status: NEW → ASSIGNED
Pushed by kcochrane@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/44765b0ec9a1 https://hg.mozilla.org/integration/autoland/rev/e755df51b7f1 Remember expanded/collapsed state of windows in open tabs sidebar panel r=kcochrane,sfoster
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 154 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: