Skip to content

Commit 8a1f467

Browse files
feat(console): on a narrow window the sidebar is the icon rail, and a click expands it over the content (#27893)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgDFH4S5pR1C8YvYCWWsZfXx)_ ## 维护者速读 - 改了什么:窗口窄于 1416 px(分栏要的 1160 px 内容 + 展开侧栏 256 px)时,控制台侧栏挂载为图标轨;点图标轨空白处、顶栏侧栏按钮或 ⌘B 把整个侧栏浮在内容上展开,内容不挪;选导航、点外面或 Esc 收回。浮出时底部有「保持侧栏展开」,按下后这个浏览器的窄窗也保持宽窗侧栏。 - 为什么改:1280 px 的笔记本窗口里展开的侧栏只留 1024 px 内容,放不下记录分栏;折成图标轨后剩 1232 px。 - 风险与回滚:只动控制台外壳(app-shell 两个文件 + 一个新模块)、components 新增一个 hook、i18n 一个新键;`components/src/ui/**` 没碰。≥1416 px 与手机抽屉行为不变。回滚即还原本 PR。 - 先看:`ui/packages/app-shell/src/layout/consoleSidebarRail.ts`(阈值推导、浮出、收回);`ui/packages/app-shell/src/hooks/useResponsiveSidebar.ts`(折叠与宽窗状态暂存);`UnifiedSidebar.tsx` 的外框与底部开关。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/layout/__tests__/UnifiedSidebar.railOverlay-27593.test.tsx packages/app-shell/src/hooks/__tests__/useResponsiveSidebar.test.tsx`,预期全绿;或在 1280 px 窗口打开任一应用,侧栏是图标轨,点轨道空白处浮出。 - 需要你做的:无,席位落地。 Fixes #27593 Clause-②: yes (widening) Metadata-protocol: none ## What changes - **The fold (`app-shell` `useResponsiveSidebar`, extended in place).** While the window is narrower than `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` and wider than the phone breakpoint, the console sidebar is folded to its icon rail; when the window widens past it, the sidebar unfolds. It replaces the old one-time 768–1023 px collapse. A layout effect, so a window that opens narrow paints the rail first. - **The width is derived, in one named constant** (`app-shell/src/layout/consoleSidebarRail.ts`): `RECORD_SPLIT_MIN_CONTENT_WIDTH` (the split's list 440 + pane 720 = 1160) + `CONSOLE_EXPANDED_SIDEBAR_WIDTH` (256, the primitive's `--sidebar-width`; a test reads the primitive's value and holds the two equal) = 1416. A 1280 px window folds (1232 px left for the split); a 1440 px window keeps the expanded sidebar (1184 px left). - **Expand over the content (`UnifiedSidebar`, `railOverlay` prop set by `ConsoleLayout`).** A click on the rail's background, the app bar's trigger, or ⌘B / Ctrl+B expands the folded sidebar as an overlay: the fixed panel takes its expanded width above the page (`z-40`, a shadow), while a `display: contents` frame around the sidebar holds the primitive's in-flow gap at the rail width, so the content does not move. A navigation (an entry chosen in it, the command palette, Back), a press outside it, or an Esc no other layer handled folds it again. A press inside the sidebar's React tree, its entries' portaled menus included, does not; a press on the app bar's trigger is left to the trigger. Hover does nothing; a click on a rail icon opens the entry as before. - **Keep sidebar open.** The expanded overlay's footer carries one toggle, `aria-pressed`, stored per browser as the workspace preference `console.sidebar.keepOpen` (`os:pref:` store). On, a narrow window keeps the wide-window sidebar (expanded beside the content, ⌘B collapses it as on a wide window) and the toggle stays in the footer to turn it off. - **The wide window keeps its state.** The sidebar primitive writes its `sidebar_state` cookie on every open and close, the fold's included, so the fold now stashes the wide-window state (`os:console-sidebar:wide-open`) when it takes over and hands it back when the window widens, or on the next load that opens wide. - **`@object-ui/components`**: new export `useIsViewportBelow(breakpoint)` beside `useIsMobile`, read synchronously on the first render and live through `matchMedia`. - **`@object-ui/i18n`**: `sidebar.keepOpen` in all ten packs. - No change under `components/src/ui/**`, `packages/spec/**`, or any metadata key. ## Tests - New `layout/__tests__/UnifiedSidebar.railOverlay-27593.test.tsx` (11): 1280 mounts the rail; a background click expands the overlay, the panel carries the overlay classes and the frame's variant reaches the primitive's gap (not the panel); hover does not expand and a rail icon navigates; a nav choice, a route change from elsewhere, an outside press, Esc fold it; an Esc another layer handled does not; a press in an entry's portaled menu does not; the trigger toggles once; keep-open ends the fold, survives a remount, and turning it off folds again; 1440 unchanged; 700 mounts the phone drawer. - `hooks/__tests__/useResponsiveSidebar.test.tsx` rewritten (7): 1280 folds / 1440 open; a manual expand on a narrow window holds; widening hands back an open and a collapsed wide state; a wide load after a narrow one gets the wide state; keep-open; the phone breakpoint is left alone. - New `layout/__tests__/consoleSidebarRail.width-27593.test.tsx` (3): the expanded width equals the primitive's `--sidebar-width`; the derivation; 1280 / 1440 on either side. - New `components/src/hooks/__tests__/use-viewport-below.test.tsx` (3): first-render answer with no wrong frame, the breakpoint edge, live across resizes. - Two existing pins follow the new behaviour: `KeyboardShortcutsDialog.wiredOnly-11674` mounts a 1440 px window (its ⌘B probe starts from the expanded sidebar); `consoleTopBar.height-12639` reads `CONSOLE_BELOW_TOP_BAR` as the sidebar's leading class (the overlay adds its own after it). ## Acceptance notes - **Deviation: the threshold.** The card's Target 1 says "below a window width of 1100 px", while its Acceptance 1 says "at 1280 px the sidebar mounts as the icon rail … at 1440 px nothing changes" and its title says a 1280 px window keeps room for the split. A 1280 px window is wider than 1100, so the two cannot both hold. Agreed with the seat before implementing: the threshold follows the Acceptance, the title and the card's own Source derivation (the split needs 1160 px of content, the expanded sidebar is 256 px), so it is 1416 px, derived in one named constant from the sidebar's width rather than written as a number. The epic seat is asked to confirm it at the preview. - **Premise corrections (measured on `main` `ddab8b99`).** The "resizable rail (200–480 px, remembered in localStorage)" the card's Source describes does not exist: the only remembered sidebar state is the primitive's `sidebar_state` open/closed cookie. The sidebar was already `collapsible="icon"` with rail tooltips (the entries' own labels), and `useResponsiveSidebar` already collapsed it once between 768 and 1023 px, writing that into the cookie. There was no pin toggle in the expanded sidebar (the shell's one trigger is in the app bar), so "Keep sidebar open" is new, with one new i18n key. - **No edit under `components/src/ui/**`** (ui `AGENTS.md` #7): the overlay is built from the outside, through the primitive's `className` / props on the panel and a `display: contents` frame whose arbitrary variant narrows the gap (the first child of the primitive's `data-collapsible` element). The overlay test pins that the variant reaches the gap, so a primitive sync that moves it turns the test red. - **The rail's background click is a mouse convenience**; its keyboard twins are the app bar's trigger and ⌘B. The handler arrives through a props spread on the `Sidebar` element, which the clickable non-control census (`clickableNonControlCensus-13461`) does not judge. - **Record page tiers.** `recordPageColumns.ts` (plugin-detail) derives its 1120 / 760 container floors from example windows with the sidebar expanded. The tiers are container-measured, so they follow the fold on their own: at 1280 the content area is 1232 px instead of 1024, so a full record page there can now reach the wider tier. The docblock's window examples still describe an expanded sidebar; not edited here (outside this card's surface). - **HotCRM.** This container reaches only this repository, so the screenshots are taken on the in-repo CRM example (`examples/app-crm`, Contacts); the shell is app-independent. - **Docs.** No page under `content/docs/` describes the console shell's sidebar, and the components README lists no hooks; nothing to update. ## Verification All readings on head `bc7935f4` (the branch merged with `origin/main` at `c4cb5ec0`; of the files this diff edits, the merge touched only the ten locale packs, and merged them cleanly), unless a line says otherwise. <details><summary>Browser measurement (Chromium, the CRM example's Contacts list)</summary> Branch code at `fdb717ea` (pre-merge; the merge brought nothing under the edited surface), backend `objectstack dev --seed-admin --fresh` on `examples/app-crm`, console on its Vite dev server. Screenshots, readings and the script are on the never-merged evidence branch `claude/issue-27593-evidence` @ `b86187c2`, folder `evidence/27593/`. | Window, state | sidebar | gap (in flow) | panel | panel z | content left / width | |---|---|---|---|---|---| | 1280, on load | collapsed, `data-console-rail=rail` | 48 | 48 | 10 | 48 / 1232 | | 1280, rail background clicked | expanded, `overlay` | 48 | 256 | 40 | 48 / 1232 | | 1280, after Esc | collapsed | 48 | 48 | 10 | 48 / 1232 | | 1280, app bar trigger | expanded, `overlay` | 48 | 256 | 40 | 48 / 1232 | | 1280, press on the page | collapsed | 48 | 48 | 10 | 48 / 1232 | | 1440, on load | expanded, no rail attribute | 256 | 256 | 10 | 256 / 1184 | | 700, trigger | phone drawer (`data-mobile`), no desktop sidebar | – | – | – | 0 / 700 | The overlay leaves the content box exactly where it was (48 / 1232 in every 1280 state); the "Keep sidebar open" footer is present only while expanded. </details> <details><summary>Tests and type-check</summary> - New and rewritten files (4: `use-viewport-below`, `useResponsiveSidebar`, `consoleSidebarRail.width-27593`, `UnifiedSidebar.railOverlay-27593`): Test Files 4 passed (4), Tests 24 passed (24); os-verify-lock VERDICT command-exit 0. - Every existing test file that names `UnifiedSidebar`, `ConsoleLayout`, `useResponsiveSidebar`, `LocalizedSidebarTrigger` or the `sidebar_state` cookie (135 files) plus `packages/i18n/`, on `48346663`: Test Files 2 failed | 223 passed (225), Tests 2 failed | 2443 passed | 13 skipped. The two were the pins this PR updates (`KeyboardShortcutsDialog.wiredOnly-11674`: its ⌘B probe mounted at happy-dom's default 1024 px and expected an expanded sidebar; `consoleTopBar.height-12639`: its source regex read `className={CONSOLE_BELOW_TOP_BAR}` verbatim); after the update both files pass (17/17). - On the merged head `bc7935f4`, after rebuilding `@object-ui/i18n` and `@object-ui/components`: `type-check` of `@object-ui/components` and `@object-ui/app-shell` (tsc --noEmit and tsconfig.test.json) exit 0, and the four new files, the two updated pins, `LocalizedSidebarTrigger.appBar-12429` and `packages/i18n/`: Test Files 98 passed (98), Tests 1428 passed | 13 skipped; VERDICT command-exit 0. - Ablations, one per behaviour, each through `scripts/ablation-replace.mjs` (anchor 1 -> 0, blob changed, restored, `git diff HEAD` empty after); app-shell tests import `src`, so no dist rebuild: - the frame's gap-keeping class removed: 1 failed | 17 passed — "the gap keeps the rail's width"; - the wide-state stash write removed: 5 failed | 13 passed — every hand-back case, and the phone-breakpoint case (its transient fold is no longer undone); - the inside-press check removed: 1 failed | 17 passed — "a press in an entry's own menu, drawn in a portal, does not fold it". - `pnpm --dir ui run check:i18n-drift` (1 key added, 0 en values changed), `check:i18n-keys`, `check:i18n-dead-keys`: exit 0. `pnpm --dir ui run check:new-line-citations`: 0 new, exit 0. - Not run locally, left to CI's Test UI shards: the rest of the `components`, `app-shell` and `i18n`-consuming suites. </details> <details><summary>Gates</summary> - `dispatch-gates --commands` on `bc7935f4` derived 35 families; all 35 ran, each `exit 0` (`check-sdui-manifest` and its `--self-test`, and `pnpm --dir ui exec vitest run scripts/`, among them). `--ran` reconciliation: 35 derived, 35 run, 0 NOT-MEASURED, 0 UNRUN. - Repo-wide families and Test UI belong to CI; see this PR's check-runs. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CaPpqK4cmqg5XJnjsj --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CaPpqK4cmqg5XJnjsj)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f3fe660 commit 8a1f467

23 files changed

Lines changed: 1007 additions & 56 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/i18n': patch
4+
'@object-ui/app-shell': patch
5+
---
6+
7+
feat(console): on a narrow window the sidebar is the icon rail, and a click expands it over the content
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
On a 1280 px laptop window the expanded console sidebar left 1024 px of content, too little for a record's split view beside its list. Now:
13+
14+
- **The fold.** Below the width the record split needs beside an expanded sidebar (its 1160 px of content plus the 256 px sidebar, so 1416 px), the console sidebar mounts as the icon rail and the content takes the rest. At that width and above the sidebar behaves as before; below the phone breakpoint the drawer is unchanged. The width is derived in one named constant, `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH`, from the sidebar's own width.
15+
- **Expand over the content.** A click on the rail's background, the app bar's sidebar button or ⌘B / Ctrl+B expands the full sidebar over the page without moving it; choosing a navigation entry, a press outside it or Esc folds it again. Hovering does nothing, and a click on a rail icon still opens that entry.
16+
- **Keep sidebar open.** While the rail is expanded, its foot offers "Keep sidebar open": pressed, the narrow window keeps the wide-window sidebar in this browser, and pressing it again brings the fold back.
17+
- **The wide window keeps its state.** The open or collapsed state the reader chose on a wide window is no longer overwritten by the fold: it comes back when the window widens, and on the next load that opens wide.
18+
19+
`@object-ui/components`: new `useIsViewportBelow(breakpoint)` hook, `true` while the window is narrower than `breakpoint` CSS pixels, read synchronously on the first render and live through `matchMedia`. Nothing existing changes.
20+
21+
`@object-ui/i18n`: the `sidebar` namespace gains `sidebar.keepOpen` in all ten packs. No key is removed or renamed.

‎ui/packages/app-shell/src/chrome/KeyboardShortcutsDialog.wiredOnly-11674.test.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ function readAdvertised(): Array<{ id: string; chord: ShortcutChord }> {
118118

119119
/** The console chrome as `AppContent` composes it, with the dialog inside. */
120120
function mountConsole(path: string) {
121+
// A wide window: below `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` the console folds
122+
// the sidebar to its rail on mount (objectstack#27593), and the sidebar
123+
// probe starts from the expanded sidebar.
124+
(window as unknown as { happyDOM: { setViewport: (v: { width: number; height: number }) => void } }).happyDOM.setViewport({
125+
width: 1440,
126+
height: 900,
127+
});
121128
return render(
122129
<MemoryRouter initialEntries={[path]}>
123130
<NavigationProvider>
Lines changed: 121 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,148 @@
1-
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* useResponsiveSidebar — the sidebar folds to its icon rail on a window
5+
* narrower than `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` and unfolds when it widens
6+
* (objectstack#27593). The wide window's open state survives the fold, a
7+
* reader's "keep open" turns the fold off, and the phone drawer is left alone.
8+
*/
9+
10+
import '@testing-library/jest-dom/vitest';
11+
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
212
import { SidebarProvider, useSidebar } from '@object-ui/components';
3-
import { describe, expect, it } from 'vitest';
13+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
414
import { useResponsiveSidebar } from '../useResponsiveSidebar';
15+
import {
16+
CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE,
17+
readStashedWideOpen,
18+
} from '../../layout/consoleSidebarRail';
19+
import { writeWorkspacePreference } from '../../utils/workspacePreference';
520

21+
/**
22+
* Size the test window: happy-dom's own viewport, so `innerWidth`, the
23+
* `resize` event and every media query answer the same width.
24+
*/
625
function setViewportWidth(width: number) {
7-
Object.defineProperty(window, 'innerWidth', {
8-
configurable: true,
9-
writable: true,
10-
value: width,
26+
(window as unknown as { happyDOM: { setViewport: (v: { width: number; height: number }) => void } }).happyDOM.setViewport({
27+
width,
28+
height: 900,
29+
});
30+
}
31+
32+
/** Resize a mounted window; happy-dom dispatches the `resize` its media queries answer. */
33+
function resizeTo(width: number) {
34+
act(() => {
35+
setViewportWidth(width);
1136
});
1237
}
1338

1439
function Harness() {
1540
useResponsiveSidebar();
16-
const { open, setOpen } = useSidebar();
41+
const { open, setOpen, toggleSidebar } = useSidebar();
1742

1843
return (
1944
<>
2045
<div data-testid="sidebar-open">{String(open)}</div>
2146
<button type="button" onClick={() => setOpen(true)}>
2247
Expand sidebar
2348
</button>
49+
<button type="button" onClick={toggleSidebar}>
50+
Toggle sidebar
51+
</button>
2452
</>
2553
);
2654
}
2755

28-
describe('useResponsiveSidebar', () => {
29-
it('auto-collapses at tablet width without overriding a manual expand', async () => {
30-
setViewportWidth(970);
56+
function renderAt(width: number) {
57+
setViewportWidth(width);
58+
return render(
59+
<SidebarProvider defaultOpen>
60+
<Harness />
61+
</SidebarProvider>,
62+
);
63+
}
64+
65+
const openState = () => screen.getByTestId('sidebar-open').textContent;
66+
67+
beforeEach(() => {
68+
localStorage.clear();
69+
document.cookie = 'sidebar_state=; path=/; max-age=0';
70+
});
71+
72+
afterEach(() => {
73+
cleanup();
74+
setViewportWidth(1024);
75+
localStorage.clear();
76+
document.cookie = 'sidebar_state=; path=/; max-age=0';
77+
});
78+
79+
describe('useResponsiveSidebar (objectstack#27593)', () => {
80+
it('folds the sidebar on a 1280 px window and leaves it open on a 1440 px one', () => {
81+
renderAt(1280);
82+
expect(openState()).toBe('false');
83+
cleanup();
84+
85+
renderAt(1440);
86+
expect(openState()).toBe('true');
87+
});
88+
89+
it('keeps a manual expand on a narrow window (the rail expanded over the content)', () => {
90+
renderAt(970);
91+
expect(openState()).toBe('false');
92+
93+
fireEvent.click(screen.getByRole('button', { name: 'Expand sidebar' }));
94+
expect(openState()).toBe('true');
95+
});
96+
97+
it('hands the wide state back when the window widens, and folds again when it narrows', () => {
98+
renderAt(1440);
99+
expect(openState()).toBe('true');
31100

32-
render(
33-
<SidebarProvider defaultOpen>
34-
<Harness />
35-
</SidebarProvider>,
36-
);
101+
resizeTo(1280);
102+
expect(openState()).toBe('false');
103+
expect(readStashedWideOpen()).toBe(true);
104+
105+
resizeTo(1440);
106+
expect(openState()).toBe('true');
107+
expect(readStashedWideOpen()).toBeUndefined();
108+
});
37109

38-
await waitFor(() => {
39-
expect(screen.getByTestId('sidebar-open')).toHaveTextContent('false');
40-
});
110+
it('hands back a collapsed wide state as collapsed', () => {
111+
renderAt(1440);
112+
fireEvent.click(screen.getByRole('button', { name: 'Toggle sidebar' }));
113+
expect(openState()).toBe('false');
41114

115+
resizeTo(1280);
116+
// The reader expands the rail over the content on the narrow window…
42117
fireEvent.click(screen.getByRole('button', { name: 'Expand sidebar' }));
118+
expect(openState()).toBe('true');
119+
120+
// …and the wide window gets back the state the reader left it in.
121+
resizeTo(1440);
122+
expect(openState()).toBe('false');
123+
});
124+
125+
it('a load that opens wide after a narrow one gets the wide state back, not the fold', () => {
126+
renderAt(1280);
127+
expect(openState()).toBe('false');
128+
cleanup();
129+
130+
// The primitive's cookie recorded the fold; the stash carries the wide state.
131+
renderAt(1440);
132+
expect(openState()).toBe('true');
133+
expect(readStashedWideOpen()).toBeUndefined();
134+
});
135+
136+
it('"keep open" turns the fold off: a narrow window keeps the sidebar open', () => {
137+
writeWorkspacePreference(CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE, 'user', 'on');
138+
renderAt(1280);
139+
expect(openState()).toBe('true');
140+
expect(readStashedWideOpen()).toBeUndefined();
141+
});
43142

44-
await waitFor(() => {
45-
expect(screen.getByTestId('sidebar-open')).toHaveTextContent('true');
46-
});
143+
it('leaves the open state alone below the phone breakpoint, where the drawer takes over', () => {
144+
renderAt(700);
145+
expect(openState()).toBe('true');
146+
expect(readStashedWideOpen()).toBeUndefined();
47147
});
48148
});
Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,52 @@
11
/**
22
* useResponsiveSidebar
33
*
4-
* Auto-collapses the sidebar on tablet-width viewports (768px–1023px).
4+
* Folds the sidebar to its icon rail while the window is narrower than
5+
* `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` (and wider than the phone breakpoint,
6+
* where the drawer takes over), and unfolds it when the window widens again
7+
* (objectstack#27593). A reader who keeps the sidebar open is left alone.
58
* Must be called inside a SidebarProvider context.
9+
*
10+
* The fold is not the reader's choice, so it does not keep one: the open
11+
* state the sidebar had on the wide window is stashed when the rail takes
12+
* over and handed back when the window widens, or on the next load that
13+
* opens wide, because the primitive's cookie records every open and close,
14+
* the fold's included.
615
* @module
716
*/
817

9-
import { useEffect, useRef } from 'react';
18+
import { useLayoutEffect, useRef } from 'react';
1019
import { useSidebar } from '@object-ui/components';
11-
12-
/** Tablet breakpoint range: 768px <= width < 1024px */
13-
const TABLET_MIN = 768;
14-
const TABLET_MAX = 1024;
20+
import {
21+
readStashedWideOpen,
22+
useConsoleSidebarRail,
23+
writeStashedWideOpen,
24+
} from '../layout/consoleSidebarRail.js';
1525

1626
export function useResponsiveSidebar() {
17-
const { setOpen, isMobile } = useSidebar();
27+
const { open, setOpen } = useSidebar();
28+
const { narrow, keepOpen, railMode } = useConsoleSidebarRail();
29+
const openRef = useRef(open);
1830
const setOpenRef = useRef(setOpen);
1931

20-
useEffect(() => {
32+
useLayoutEffect(() => {
33+
openRef.current = open;
2134
setOpenRef.current = setOpen;
22-
}, [setOpen]);
23-
24-
useEffect(() => {
25-
if (isMobile) return undefined;
26-
27-
let wasTablet = false;
28-
29-
function handleResize() {
30-
const width = window.innerWidth;
31-
const isTablet = width >= TABLET_MIN && width < TABLET_MAX;
32-
if (isTablet && !wasTablet) {
33-
// Auto-collapse once when entering tablet width, then preserve manual toggles.
34-
setOpenRef.current(false);
35-
}
36-
wasTablet = isTablet;
35+
});
36+
37+
// A layout effect, so a window that opens narrow paints the rail first.
38+
useLayoutEffect(() => {
39+
if (railMode) {
40+
// A stash left by an earlier narrow load is the wide state; keep it.
41+
if (readStashedWideOpen() === undefined) writeStashedWideOpen(openRef.current);
42+
setOpenRef.current(false);
43+
return;
3744
}
38-
39-
// Run on mount to set initial state
40-
handleResize();
41-
42-
window.addEventListener('resize', handleResize);
43-
return () => window.removeEventListener('resize', handleResize);
44-
}, [isMobile]);
45+
const wideOpen = readStashedWideOpen();
46+
if (wideOpen === undefined) return;
47+
writeStashedWideOpen(undefined);
48+
// "Keep open" on a narrow window: the reader just chose the open sidebar.
49+
if (narrow && keepOpen) return;
50+
setOpenRef.current(wideOpen);
51+
}, [railMode, narrow, keepOpen]);
4552
}

‎ui/packages/app-shell/src/layout/ConsoleLayout.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ export function ConsoleLayout({
216216
<UnifiedSidebar
217217
activeAppName={activeAppName}
218218
onAppChange={onAppChange}
219+
railOverlay
219220
/>
220221
}
221222
navbar={

0 commit comments

Comments
 (0)