Skip to content

Plan the VS Code UI's toolbar with the shared fit plan - #109

Merged
agorischek merged 2 commits into
mainfrom
vscode-ui-shared-fit-plan
Nov 21, 2026
Merged

agorischek merged 2 commits into
mainfrom
vscode-ui-shared-fit-plan

Conversation

@agorischek

@agorischek agorischek commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #106 (base review-f15-headless-fit-plan). Follow-up to code review, finding 15 ("Responsive toolbar machinery has forked across UI layers"): the public VS Code UI had a third copy of the toolbar layout machinery, so this moves it onto the shared fit plan.

What moved

packages/host/vscode-ui/src/layout/ kept its own copy of:

  • the measurement cache, including shifting stale needs and carrying them across collapse orders;
  • the step chooser;
  • a ResizeObserver on the toolbar and another on its start region;
  • the re-measure once VSCode Elements finish rendering;
  • the focus-follow hook.

use-toolbar-layout.ts now calls useFitPlan from @githubnext/projections-host. focus.ts is deleted, and choose and carryStep are gone from steps.ts. Neither was exported from the package.

What stays UI-owned

  • The steps (toolbarSteps), rowForm, and the new locateStep. locateStep returns the step itself, else the first step with the same row 1 form, else the first step; that is the step half of the old carryStep.
  • The measurement (requiredWidth, with its centred-row and second-row needs).
  • The 32px toolbarHysteresis.
  • The focusFallbacks table and focusControl, which reaches through shadow roots.

Options the shared hook gains

The VS Code UI and Primer share the same algorithm, so these options let either express it:

Option Replaces in the VS Code UI
key may be a function of the width the narrow-boundary flag (width < narrowToolbarWidth): the slider's minimum drops below 480px
shiftNeeds the stale flag: a new key, a resized region or a settled pending keeps the needs and moves them all by the shown plan's change
carry(plan) the needs half of carryStep: a new set of plans takes the needs of the previous plans with the same carry key (rowForm); if the shown plan's key is gone, everything is measured again
need(plan, measured) the shared rowNeed: two-row inline steps use max(own, rowNeed), and an unknown rowNeed tries the step
pending(element) the VSCode Elements updateComplete re-measure
regions (selector, default [data-toolbar-region]) the start-region observer (:scope > .phv-toolbar-start)
focusControl focusControl in focus follow

Primer can use shiftNeeds, need and the width-dependent key for its stale/narrow shifting and its rowNeed. That closes the one difference called out in #106's follow-up.

Behaviour

The steps chosen at rest are the same.

The shared lifecycle brings a few deliberate differences:

  • The toolbar now carries data-fit-settled.
  • A deliberate blur isn't undone by a later remount (Plan bars with a headless fit plan shared by every UI #106's focus fix).
  • A bar without width (a hidden tab) keeps its plan instead of being measured at 0. This also applies to the default UI and the Inspector title bar, where collapsing a hidden bar to its last plan was never useful.

Two sub-pixel or transient differences:

  • The shared chooser compares a need against the width with half a pixel of tolerance, where this UI floored the width.
  • During a replanning burst, hysteresis is anchored on the last settled step rather than the step being tried. Both reach the same settled result.

The bound on oscillation now counts only switches between measured plans, not settles. A region whose width differs from what it was when the bar settled, or a settled pending, starts a new burst, so repeated notices at one width can still replan (from review). This applies to every bar.

The default UI passes none of the new options, so it behaves as in #106 apart from the zero-width rule.

Tests

  • packages/host/core/test/fit-plan.test.mjs: a new case covers needs carried by key (and not carried when the shown plan's form is gone), and needs shifted alike when the shown plan measures differently.
  • packages/host/vscode-ui/test/toolbar-steps.test.mjs: the carryStep cases now cover locateStep. Playback coming or going keeps row 1's form and goes back again, a step stays itself in its own order, and the first step is used when the form is gone.
  • Run locally:
    • tools check --fast passed.
    • tsc passed for host/core and vscode-ui, src and browser tsconfigs.
    • node --test passed: host/core fit-plan and toolbar-layout 9/9, vscode-ui all 25/25.
    • I didn't use tools build, because it would build the engine's Rust/Wasm. The browser suites (vscode-ui's vscode.spec.ts focus checks, Storybook smoke) run in CI.

State machine

This is rebased on #106, which now runs the fit plan's lifecycle as fitPlanLifecycle, built on @githubnext/projections-machine. The new options fit into it:

  • pending content that settles sends a rendered event, which measures again (a new run). It is ignored while a replan already waits for a press to be released, since the release measures again anyway. Its staleness guard (key or the plans changed) is unchanged.
  • The region widths that d674cbf's fresh burst compares against are recorded as the hook sends fitted.
  • The VS Code UI's use-toolbar-layout.ts no longer starts a timer, so its lifecycle baseline drops from 1 to none (check-machines.mjs --update).
  • After One-row toolbar, a floating glass foot for the legend and summary, and extraction said on the stage #65, the modes lead the row by default, so toolbar-steps.test.mjs keeps main's centre: true fixtures with this PR's locateStep assertions.

Queue

#58, #65 and #77 have merged. This PR is rebased on #106, which is rebased on main, and merges after #106. It stays out of packages/host/core/src/ui/toolbar-layout.ts and docs/guides/host-core.md; the new options are documented in TSDoc only.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Repeated region changes exhaust the replanning budget, potentially leaving the toolbar unnecessarily collapsed or overflowing even when a cached plan fits.

1 open issue
What changed in this PR

Moves the VS Code UI’s responsive toolbar onto host core’s shared useFitPlan, continuing #106’s consolidation while keeping UI-specific layout rules and measurements.

Changes:

  • Extends the shared hook with cache shifting and carrying, width-dependent keys, pending-render measurement, and custom region and focus handling.
  • Removes duplicated VS Code toolbar lifecycle logic while preserving its steps and 32px hysteresis.
  • Updates unit tests and package documentation for the shared implementation.
File Description
packages/​host/​vscode-ui/​test/​toolbar-steps.test.mjs Replaces carry-step tests with step-location coverage.
packages/​host/​vscode-ui/​src/​layout/​use-toolbar-layout.ts Delegates layout lifecycle to useFitPlan.
packages/​host/​vscode-ui/​src/​layout/​steps.ts Adds locateStep and removes duplicated choosing and carrying logic.
packages/​host/​vscode-ui/​src/​layout/​focus.ts Deletes the UI-specific focus-follow hook.
packages/​host/​vscode-ui/​README.md Documents shared toolbar planning.
packages/​host/​core/​test/​fit-plan.test.mjs Tests measurement carrying and shifting.
packages/​host/​core/​src/​fit-plan/​needs.ts Adds shared measurement-cache helpers.
packages/​host/​core/​src/​fit-plan/​focus.ts Supports custom focus restoration.
packages/​host/​core/​src/​fit-plan.ts Adds migration options and preserves plans for hidden bars.

Review effort: Balanced

Comment thread packages/host/core/src/fit-plan.ts Resolved
@agorischek
agorischek force-pushed the review-f15-headless-fit-plan branch from 9cecdc4 to 3d438ed Compare November 21, 2026 15:33
@agorischek
agorischek force-pushed the vscode-ui-shared-fit-plan branch from d674cbf to bae99c8 Compare November 21, 2026 15:33
@agorischek
agorischek force-pushed the review-f15-headless-fit-plan branch from 3d438ed to b47beb3 Compare November 21, 2026 16:17
@agorischek
agorischek force-pushed the vscode-ui-shared-fit-plan branch from bae99c8 to 822dba4 Compare November 21, 2026 16:17
Base automatically changed from review-f15-headless-fit-plan to main November 21, 2026 17:33
agorischek and others added 2 commits November 21, 2026 09:38
The VS Code UI's own measurement cache, step choice, resize observers and
focus follow give way to the host core's `useFitPlan`. Its steps, measurement
and 32px hysteresis stay its own; the shared hook gains the options its
algorithm (and Primer's) needs: needs shifted alike on new content
(`shiftNeeds`), needs carried to a new collapse order (`carry`), a need shared
between plans (`need`), a width-dependent `key`, custom elements still
rendering (`pending`), the observed `regions` and `focusControl`. A bar
without width keeps its plan.

Content that settles is a `rendered` event of `fitPlanLifecycle`: it measures
again, unless a replan already waits for a press to be released. The VS Code
UI's toolbar hook no longer starts a timer, so its lifecycle baseline drops to
none.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Only switches between measured plans count towards the burst that bounds
oscillation, not settles. A region that isn't as wide as when the bar settled,
or content that finished rendering (`pending`), starts a new burst, so repeated
notices at one width and content key can still replan; resize notifications
from the plan the bar settled on leave the regions as wide as they were and
keep the bound.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek force-pushed the vscode-ui-shared-fit-plan branch from 822dba4 to 93e1215 Compare November 21, 2026 17:38
@agorischek
agorischek merged commit 2e210e5 into main Nov 21, 2026
53 checks passed
@agorischek
agorischek deleted the vscode-ui-shared-fit-plan branch November 21, 2026 18:13
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.

2 participants