Skip to content

no-bug: Reopen tabs in the destination Space's container when moving between Spaces - #14750

Open
joegoldin wants to merge 3 commits into
zen-browser:devfrom
joegoldin:feat/space-container-routing
Open

no-bug: Reopen tabs in the destination Space's container when moving between Spaces#14750
joegoldin wants to merge 3 commits into
zen-browser:devfrom
joegoldin:feat/space-container-routing

Conversation

@joegoldin

Copy link
Copy Markdown
Contributor

What this fixes

Moving a tab into a Space that has a default container left the tab in its old container. The tab now sits in a Space whose container it doesn't belong to, and nothing in the UI says so, because the container marker was decided once at tab creation and never recomputed.

Two changes: move the tab into the destination Space's container, and make the marker reflect the Space you're actually looking at.

Reopening in the destination container

Firefox can't change a tab's userContextId in place, so the tab has to be reopened. reopenTabInWorkspaceContainerIfNeeded() copies the tab's SessionStore state (URL, full session history, pinned state), sets the new container and Space on the copy, restores it, and closes the original. Selection follows the tab, and a tab that wasn't selected is recreated lazily so moving a batch of background tabs doesn't force a load.

It returns the original tab untouched when there's nothing to do: the destination Space has no default container, the tab is already in that container, or the tab is one whose DOM relationships would break if it were recreated (essentials, the empty-tab placeholder, glance tabs, and members of a split-view group). If the reopen throws partway through, selection is put back on the original tab and the half-built replacement is discarded, so a failure costs you nothing.

Both paths that move tabs between Spaces use it: the tab context menu's "move to Space" action, and dropping a tab onto a Space in the sidebar.

One incidental change in changeTabWorkspace: the tab to select afterwards is now read before moveTabsToWorkspace rather than after. That function reverses its argument array in place when zen.view.show-newtab-button-top is set, which defaults to true, so reading afterwards picked the first of a multi-tab selection instead of the last. Single-tab moves, the common case, are unaffected.

Making the container marker mean something

The marker was driven by a zenDefaultUserContextId attribute written when the tab was created, so it only ever described the Space the tab was born in. Once a Space had a container configured, tabs whose container differed from it showed nothing.

updateTabContainerIndicators() now recomputes the marker for the active Space's tabs against that Space's default container, and runs whenever the reference container can change: on Space switch, when a Space's container is reconfigured, and when tabs are added or moved. A tab shows the marker when its container differs from the Space default and hides it when they match.

Container-less tabs needed a separate case. Firefox only colours the marker when a tab has a userContextId, so a tab with no container sitting in a Space that does have one would render nothing at all, which is exactly the case the user needs to see. Those get a zen-neutral-container-marker attribute and a gray marker, since there's no container colour to borrow.

Testing

Built against Firefox 153. This branch adds no automated tests; the behaviour is exercised through the Space Routing suite, which covers the container resolution it builds on.

@joegoldin
joegoldin marked this pull request as ready for review July 28, 2026 05:17
@joegoldin
joegoldin requested a review from mr-cheffy as a code owner July 28, 2026 05:17
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 28, 2026
@joegoldin

Copy link
Copy Markdown
Contributor Author

I've also been running this on my machine for a while without issues

joegoldin added a commit to joegoldin/zen-browser-desktop that referenced this pull request Jul 28, 2026
Upstream closed zen-browser#14751, so only zen-browser#14750 (container routing on Space move)
is still open. Corrects the README and the branch model, which described
feat/nix-flake as held off dev pending review that is not happening.
@joegoldin joegoldin closed this Jul 29, 2026
@joegoldin
joegoldin deleted the feat/space-container-routing branch July 29, 2026 04:42
@joegoldin
joegoldin restored the feat/space-container-routing branch July 29, 2026 04:43
@joegoldin joegoldin reopened this Jul 29, 2026
When moving a tab to another space, reopen it in that space's container (if
one is set) instead of leaving it in the previous space's container. Adds
reopenTabInWorkspaceContainerIfNeeded() and wires it into the context-menu
'move to space' action and the drag-and-drop drop-onto-space path.

Also fix space routing so it honors a route's destination container even when
that container is the default/no container (0): tabbrowser now keys off
isRouteFound instead of the truthiness of userContextId, so a routed tab no
longer inherits the active space's container.
The container indicator was driven by a static zenDefaultUserContextId
attribute set at tab creation, so it only reflected the space a tab was born
in. Once a space had a default container set, the marker never updated for
tabs whose container differed from it.

Recompute the marker dynamically against the active space's default container
(on space change, when a space's container is reconfigured, and when tabs are
moved/created), so a tab shows the marker whenever its container differs from
the space's default. Container-less tabs in a space that has a default
container get a neutral gray marker, since there is no container colour to
show.
- Wrap an over-length condition so the file passes 'mach lint zen' (Prettier).
- Restore selection to the original tab if reopening fails after selection
  already moved to the new tab, before discarding it.
- Correct the comment on the post-workspace-switch indicator refresh: it runs
  on every space switch, not only when the default container changes.
@joegoldin
joegoldin force-pushed the feat/space-container-routing branch from 7a0a610 to 661b44f Compare July 29, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant