Repository navigation
Plan bars with a headless fit plan shared by every UI - #106
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Intentional blur can be undone by stale focus restoration, and the fallback-focus test can pass without exercising restoration because React reuses the button node.
2 open issues
What changed in this PR
Extracts responsive bar planning into the headless host core so different UIs can share measurement and interaction handling while keeping their own layout policies. Existing default UI exports remain compatible; Primer and VS Code adoption are follow-ups.
Changes:
- Exposes the shared hook, pure plan chooser, width measurement, and configurable layout policies.
- Adds focus retention for remounted controls and overflow fallbacks.
- Adds unit tests, browser coverage, a Storybook harness, and API documentation.
| File | Description |
|---|---|
tools/storybook/harness/host/fit-plan.tsx |
Adds a plain-control fit-plan harness. |
tools/storybook/harness/host.stories.tsx |
Registers the harness story. |
packages/host/core/test/fit-plan.test.mjs |
Tests thresholds, hysteresis, and content changes. |
packages/host/core/src/ui/toolbar-layout.ts |
Imports the shared core hook. |
packages/host/core/src/ui/fit-plan.ts |
Preserves existing UI exports through re-exports. |
packages/host/core/src/ui/components/README.md |
Documents the hook’s new core location. |
packages/host/core/src/index.ts |
Exports the shared planning API. |
packages/host/core/src/fit-plan/focus.ts |
Adds focus tracking and restoration. |
packages/host/core/src/fit-plan/fit-width.ts |
Extracts DOM width measurement. |
packages/host/core/src/fit-plan/choose.ts |
Extracts pure plan selection with configurable hysteresis. |
packages/host/core/src/fit-plan.ts |
Centralizes the hook and configurable lifecycle. |
packages/host/core/browser/README.md |
Describes interaction coverage. |
packages/host/core/browser/fit-plan.spec.ts |
Tests focus retention and press-to-click behavior. |
docs/guides/host-core.md |
Documents planned bars and UI-owned options. |
Review effort: Balanced
This was referenced Nov 20, 2026
agorischek
force-pushed
the
review-f15-headless-fit-plan
branch
from
November 21, 2026 15:33
9cecdc4 to
3d438ed
Compare
The default UI's fit-plan lifecycle (the measurement cache, the observed bar and regions, the settled marker and the press-to-click lock) moves to the host's headless core as `useFitPlan`, with focus retention for controls marked `data-focus-id` (`focusFallbacks`), a `measure` hook, a per-transition `hysteresis` and the pure `chooseFitPlan`. The default UI's names stay exported from `./ui` and `./ui/components`. Code review, finding 15. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Focus retention restores focus only after a remount: focus that leaves the bar while its control stays mounted clears the remembered control. The harness keys Zoom and More, so the overflow fallback is really exercised, and the spec checks an intentional blur stays put. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Storybook renders a story after the page loads, so querying `.fit-sized` right after `goto` could find nothing. The locator's `evaluate` waits for it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`fitPlanLifecycle` names what `useFitPlan` kept in refs, effect timers and deferred setState: planning, settled (locked while a lock holds the plan), held (focus moved during a press, so the replan waits for the release) and releasing (the replan after focus has finished moving, an `after` timer). The frame after a resize is an activity, and the settled marker follows the state. The measured needs stay with the hook. Its explore test checks that no replan comes while a pointer is pressed, and the lifecycle baseline drops `ui/fit-plan.ts` to none. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
agorischek
force-pushed
the
review-f15-headless-fit-plan
branch
from
November 21, 2026 16:17
3d438ed to
b47beb3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Code review, finding 15: responsive toolbar machinery has forked across UI layers.
Evidence
hosted/host-primer/src/layout.ts:132-196,222-326keeps its own measurement cache, collapse selection, resize observation, hysteresis and focus recovery.packages/host/core/src/ui/fit-plan.ts:35-89,118-156,159-236has a generic fit-plan engine with region observation, a settled marker and a focus/pointer interaction lock.The two UIs may legitimately choose different collapse plans and spacing. The trouble is that each one has to work out the hard measurement and interaction lifecycle on its own. Primer restores focus after a remount but has no guard against replanning while a control is pressed. The default UI has that guard but no focus restore.
The user approved this: "playground will never move to Shad Cn that's always gonna do a little bit of its custom thing and so I think that moving our layout logic into a headless shared whatever thing um makes sense".
The module
packages/host/core/src/fit-plan.ts(withfit-plan/choose.ts,fit-plan/fit-width.tsandfit-plan/focus.ts) has no shadcn, noui/imports and no styling; it uses React. It is exported from the main@githubnext/projections-hostentry:The shared module owns the lifecycle:
key(the content) changes;data-toolbar-regionelements, replanning on the next frame;data-fit-settledon the bar once a plan settles;data-focus-idcontrol, focus moves to its new form, or else to the first offocusFallbacks[id]that the bar holds.As a state machine
The lifecycle is an explicit machine,
fitPlanLifecycle(fit-plan/lifecycle.ts, built on@githubnext/projections-machine; seedocs/guides/state-machines.md), rather than refs, effect timers andsetStatefrom timer callbacks. That's what the machines lifecycle check (tools/scripts/check-machines.mjs) asks for: the four patterns moved out ofui/fit-plan.tswould otherwise have been new debt infit-plan.ts. The baseline can only shrink, so--updatewon't move debt from one file to another.planning(the bar is measured as rendered and other plans are tried),settled(lockedwhile a lock holds the plan),held(focus moved during a press, so the replan waits for the release) andreleasing(the replan once focus has finished moving).hand: 'free' | 'pressing'andframe(a resize waits for the next frame).requestAnimationFrame, rendered synchronously withflushSyncas before), and the replan after focus moves is anaftertimer (0 ms).resized,tried,fitted).data-fit-settledfollows the state.The explore test walks every state and checks that no replan is pending while a pointer is pressed, that the frame activity runs exactly while a resize waits, and that every listed handler is reachable.
ui/fit-plan.ts's baseline drops from 4 to none, andfit-plan.tshas none.What stays UI-owned
Plans and their order, and these hooks in
FitPlanOptions:measure(element, plan), defaulting tofitWidth(element);hysteresis?: number | ((from, to, element) => number), defaulting totoolbarHysteresis(24). Each UI keeps its own value; Primer's is 32. Withfrom === to, the function sets how far past its ceiling the settled plan may stay.signature,locate,lockandceiling;focusFallbacksand thedata-focus-idmarkers.How Primer's rules map onto the options
rowNeed(two-row plans with the steps inline must also leave the sliderplaybackRowShareof row 2).measurereturnsMath.max(need, rowNeed)for those plans andneedfor the rest, using Primer's existingrequiredWidth. A plan that hasn't been measured is tried first, just as Primer tries a step whoserowNeedis unknown.firstRowSharefull).hysteresis: (from, to, element) => from.rows === 2 && to.rows === 1 && sparseFirstRow(element) ? 0 : 32. The bar is passed as rendered, sosparseFirstRowreads it unchanged. The chooser only asks about plans fuller than the settled one, which is exactly Primer'sindex < current.focusFallbackstakes Primer's table as it is, and itsdata-focus-idmarkers stay.Default UI
ui/fit-plan.tsnow only re-exports from../fit-plan.ts, andui/toolbar-layout.tsimports from the shared module.fitWidth,toolbarHysteresis,useFitPlanandFitPlanOptionsare still exported from./uiand./ui/componentsas before. Behaviour doesn't change: the default UI and the Inspector title bar mark nodata-focus-idcontrols, so focus retention does nothing for them, and the chooser is the same logic, extracted.Tests
packages/host/core/test/fit-plan.test.mjs(node:test, against../dist), all on the purechooseFitPlan:fitPlanLifecycle: a press holds a replan until its release, a resize waits for its frame, and anexploreof every state.packages/host/core/browser/fit-plan.spec.ts(browser, desktop Chromium and WebKit; it now waits for the story to render before sizing the bar, since Storybook renders after the page loads) runs on a new headless harness story,Harness/Default UI/Fit plan(tools/storybook/harness/host/fit-plan.tsx,?lockfor the lock):Run locally, rebased on main:
tools check --fastpassed (including the machines gate),node tools/scripts/check-machines.mjspassed, and the core's node tests passed (139).fit-plan.spec.tspassed on chromium-desktop. WebKit and the full browser suites are left to CI.Follow-up
Private repo, after the pin bump: move
hosted/host-primer/src/layout.ts'suseToolbarLayoutontouseFitPlanfrom@githubnext/projections-host, keepingtoolbarStepsas its plans and its two-row/slider and sparse-row behaviour through the options above:keyfromcontent.keyand the ladder;measurebuilt onrequiredWidth, plusrowNeed;hysteresisfunction with 32;focusFallbacks;lock(that also brings the press-to-click guard);chooseToolbarSteploop and focus effect.One difference: Primer shifts its known needs on a content change rather than measuring again, but the shared cache measures again when
keychanges.The public VS Code UI (
packages/host/vscode-ui/src/layout/) carries the same Primer-style fork and could move over the same way.