Skip to content

perf(console): the sidebar no longer redraws every entry each time the console re-renders during first load - #37722

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-xtck3b
Nov 27, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-xtck3b

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Sales · project thread

Part of #37444. Part of #37575. This is the first render-CPU cut: the sidebar's redraw cascade during the shell's boot re-renders. Both cards stay open: the larger render cost left on the list page is the grid's own re-render passes after its data lands and the per-row Radix mounts, which this PR deliberately leaves alone to stay small and easy to review.

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:所有用户打开控制台任意页面时,左侧导航不再在首屏加载期间被反复整栏重画;导航显示和操作(收藏、复制链接、在新标签打开)都不变,只是首屏更快。
  • 为什么做:属于「首屏 2.5 秒」卡的渲染 CPU 一刀(Console first screen: 1.1–1.8 s of main-thread script evaluation before LCP, mostly render work; cut first-render CPU #37575)。HTTP/2 口径下中位数:首页 2227,列表页 2675,记录页 2561 毫秒;首页已在 2.5 秒内,列表和记录页还差一些。
  • 出错会怎样:最坏情况是某个导航项的文字、图标或颜色在它的数据变化后没有及时刷新,或右键菜单用到了旧的回调;新测试分别锁住了这两种情况,改动可以整笔撤回。
  • 要你做什么:无。

What changes

While a Console page first loads, the shell re-renders about ten times as its boot reads land (auth, org, app list, permissions, translations). Each pass redrew every navigation entry, and with it each entry's ⋯ menu and tooltip: about 2,700 components a pass on the showcase app. A fiber census of the list page before 3 s counted 28,860 re-rendered components; after this change, 11.4k–14k.

  • ui/packages/layout/src/NavigationRenderer.tsx: the row renderer is wrapped in React.memo with a comparator, sameRowAnswers. Every prop is compared by identity except the three target resolvers (resolveTargetLabel, resolveTargetIcon, resolveTargetColor); when those are new functions, the comparator compares what they answer for this row (the resolved label, icon and, for object rows, colour) instead. A group row always re-renders when a resolver changes, so its children are compared one by one. The inline props type became the named NavItemRendererProps.
  • ui/packages/app-shell/src/layout/UnifiedSidebar.tsx: the template context passed to the nav keeps its identity while the user id, org id and context values are unchanged (keyed on their JSON), and the row action renderer is built by a module helper, navItemActionRenderer, memoised on togglePin and activeApp.
  • ui/packages/app-shell/src/layout/SidebarItemMenu.tsx: the menu is split into a thin shell (hooks, open state, a latest-callbacks ref written in a layout effect, stable toggleFavorite / copyLink) and a memoised SidebarItemMenuView that receives only strings and stable callbacks, so the DropdownMenu tree redraws only when its own text or entries change.
  • ui/packages/app-shell/src/console/AppContent.tsx: the expression user is built once per auth user (useMemo) and the provider's empty data is a module constant. Rebuilding both on every render gave ExpressionProvider a new value each pass, which alone made every visibility-gated entry redraw.

No behaviour, string, route or saved document changes. Changeset: patch on @object-ui/layout, @object-ui/app-shell, @object-ui/console, @objectstack/console (the Console dist ships the change).

Tests

  • New ui/packages/layout/src/__tests__/NavigationRenderer.rowMemo-37575.test.tsx (5 tests) counts renderItemAction calls across rerenders: same props redraw no row; new resolvers with the same answers redraw no row; one changed label redraws only that row; a group's children are compared one by one; a new evaluateVisibility redraws every row. Ablation: without the memo, 4 of 5 fail; with a plain React.memo (no comparator), 3 of 5 fail.
  • New ui/packages/app-shell/src/layout/__tests__/SidebarItemMenu.latestCallbacks-37575.test.tsx (2 tests): after a rerender, the favourite toggle calls the newest callback, and Copy link copies the newest address while the trigger is renamed. Ablation: capturing the callback at mount instead of through the ref fails 1 of 2.
  • @object-ui/layout and @object-ui/app-shell tests (347 files, 3246 tests) passed before the last two edits (the ref write moved into a layout effect, the action renderer moved to a module helper); after them, the 49 files touching the sidebar, the menu and the nav renderer (346 tests) passed again.
  • tsc --noEmit exit 0 in ui/packages/layout and ui/packages/app-shell, for both tsconfig.json and tsconfig.test.json.
  • eslint over the changed ui/ files: 0 errors. One advisory React-compiler warning remains in UnifiedSidebar.tsx (preserve-manual-memoization, "activeApp may be modified later"); the build does not use the React compiler.

Acceptance notes

  • Measured effect — production build (pnpm console:build at this head), objectstack start with NODE_ENV=production, behind a local HTTP/2 TLS front (the card's acceptance condition, Console first screen: home, object list and record page miss the 2.5 s LCP threshold (baseline 3.6 / 4.6 / 4.2 s); re-measure on a production build first #37444 ruling 7205984444), Lighthouse 13.6.0 desktop preset, Chrome for Testing 158 headless, 4-core container, signed in, cold cache. Five runs per page for HTTP/2, three for the HTTP/1.1 control through the same front:

    Page h2 before (main 9476092c) h2 after (this branch) h1 before h1 after
    Home 2297 2227 (2227, 2338, 2258, 2197, 2204) 3689 3658
    Object list 2837 2675 (2743, 2675, 2693, 2642, 2671) 4788 4778
    Record page 2685 2561 (2561, 2606, 2531, 2527, 2562) 4309 4468

    h2 gains: home −70, list −162, record −124 ms. Home stays under 2500 ms; list misses by 175 ms and record by 61 ms. The HTTP/1.1 control does not move outside its noise (3 runs; record's h1 runs spread 4227–4607): over HTTP/1.1 the first screen waits on queued script requests, so render CPU is not on its critical path there.

  • What is left, from what-if runs on this build (h2, 2 runs each): halving all simulated main-thread CPU (parse, compile, script and render together) gives list 2351 / record 2333; at one twentieth, 2290 / 2256. With unlimited bandwidth, both are about 1.5 s. So CPU, of which render is one part, is worth at most about 0.4 s on the list page, while bytes are worth about 1.2 s; the bytes slice (Console first screen: the eager JS closure (1.95 MB, same 120 chunks on every page) is ~2 s of LCP; slim what the shell imports eagerly #37572) is the next cut. Dropping the whole navigation is an upper bound of list 2609; dropping only the per-row tooltip and ⋯ menu gives 2635, so the sidebar is now near its floor.

  • The remaining render cost on the list page is the grid: 4–5 re-render passes after data lands (the measurement layout effects in data-table.tsx, 550–1080 components each) and the per-row Radix mount re-render (about 1,160 components). Out of scope here by the seat's ruling, recorded on Console first screen: 1.1–1.8 s of main-thread script evaluation before LCP, mostly render work; cut first-render CPU #37575.

  • L2 owed (not self-reviewed): no contract-tier read needed (no governed path; no spec or protocol change).

Verification

Two-minute check: cd ui && pnpm exec vitest run packages/layout/src/__tests__/NavigationRenderer.rowMemo-37575.test.tsx packages/app-shell/src/layout/__tests__/SidebarItemMenu.latestCallbacks-37575.test.tsx → 7 passed.

Read first: sameRowAnswers in NavigationRenderer.tsx (every prop that reaches a row must be either identity-compared or answer-compared; a prop it skipped would leave a stale row), then the shell/view split in SidebarItemMenu.tsx.

Local gates (derived by dispatch-gates.mjs --commands at the final head)

Head 1be3a932 (the gates ran at bc00135f, the same tree; only the commit message changed since). 38 derived, 38 run, each exit captured before any pipe; dispatch-gates.mjs --ran: 0 NOT-MEASURED, 0 UNRUN (exit 0). Every other family (lint, type-check lanes, Test UI, Build and E2E UI, the eager-closure budget) is CI's; this PR's check-runs are the record.

  • node scripts/check-adr-0087-registration.mjs --base origin/main → exit 0
  • node scripts/check-adr-0087-registration.mjs --self-test → exit 0
  • node scripts/check-changeset-no-major.mjs --base origin/main → exit 0
  • node scripts/check-closing-keyword-parity.mjs → exit 0
  • node scripts/check-closing-keyword-parity.mjs --self-test → exit 0
  • node scripts/check-comment-mask-corpus.mjs → exit 0
  • node scripts/check-empty-changeset.mjs --base origin/main → exit 0
  • node scripts/check-empty-changeset.mjs --self-test → exit 0
  • node scripts/check-sdui-manifest.mjs → exit 0
  • node scripts/check-sdui-manifest.mjs --self-test → exit 0
  • node scripts/ci/snapshot-next.mjs --self-test → exit 0
  • node scripts/pm/check-governed-queue-guard.mjs --self-test → exit 0
  • node scripts/pm/release-rehearsal-clone.mjs --self-test → exit 0
  • node scripts/release-pending-publish.mjs --self-test → exit 0
  • pnpm --dir ui exec vitest run scripts/ → exit 0
  • pnpm --filter @objectstack/spec run check:duration-unit-keys → exit 0
  • pnpm check:adr-anchors → exit 0
  • pnpm check:changeset-gate-self-tests → exit 0
  • pnpm check:closed-ceremony-text → exit 0
  • pnpm check:cross-package-test-inputs → exit 0
  • pnpm check:dispatcher-error-vocabulary → exit 0
  • pnpm check:driver-memory-census → exit 0
  • pnpm check:engine-double-contract → exit 0
  • pnpm check:gitlink-declared → exit 0
  • pnpm check:nul-bytes → exit 0
  • pnpm check:published-files → exit 0
  • pnpm check:query-options-erasure → exit 0
  • pnpm check:refd-timer-probe → exit 0
  • pnpm check:registry-log-declared → exit 0
  • pnpm check:rest-log-spy-declared → exit 0
  • pnpm check:skill-identifier-liveness → exit 0
  • pnpm check:test-source-alias → exit 0
  • pnpm check:tier-file-adoption → exit 0
  • pnpm check:type-check-coverage → exit 0
  • pnpm check:type-check-debt → exit 0
  • pnpm check:undeclared-dep-imports → exit 0
  • pnpm check:watch-hint-literal → exit 0
  • pnpm check:where-matcher → exit 0

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic.
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed. (not touched)
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L6bhgU8Bf564ZGXi4MfHWb


Generated by Claude Code

…e console re-renders during first load

The navigation row renderer is memoised on what each row shows (resolved
label, icon and colour), the sidebar's template context and row action
renderer keep their identity across renders, the row menu reads its latest
callbacks through a ref, and AppContent builds the expression user once per
auth user.

Claude-Session: https://claude.ai/code/session_01L6bhgU8Bf564ZGXi4MfHWb
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 26, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

席位核对 — ACCEPT · head 1be3a93 · cards #37444 / #37575 · area s2-ux · 2026-11-27T00:22Z

L1 checklist

  • Shape and relation. l1-face.mjs --pr 37722 read 13 items and flagged none; on this head 41 check-runs succeeded and 15 were expected skips, with none failed or pending; mergeable_state clean. Seven files, +462 / −60: the console's expression scope, the sidebar row renderer, the per-entry ⋯ menu, two pin tests and one patch changeset (@object-ui/layout, @object-ui/app-shell, both consoles).
  • Part of #37444 and Part of #37575 are right. This is the first render-CPU cut, the sidebar's redraw cascade during boot re-renders. Console first screen: home, object list and record page miss the 2.5 s LCP threshold (baseline 3.6 / 4.6 / 4.2 s); re-measure on a production build first #37444's acceptance, as amended in 7205984444 (HTTPS + HTTP/2), still fails on list and record pages: h2 medians 2297/2837/2685 → 2227/2675/2561 ms. Console first screen: 1.1–1.8 s of main-thread script evaluation before LCP, mostly render work; cut first-render CPU #37575 keeps the grid's re-render passes and per-row Radix mounts (reading 7206097776). Both cards stay pm:dispatched.
  • Design read. A row is memoised; every prop is compared by identity except the three target resolvers, which are compared by the label, icon and tile colour they answer for that row. A group with any new resolver redraws. I checked the stale-gate risk against the hosts. checkPermission / checkCapability / evaluateVisibility (useNavMemberGates) are useCallbacks keyed on the permission state, the registered-object sets and the evaluator. The doc-target checker is a useMemo. So a gate whose answer can change gets a new identity, and the rows redraw. The template context is keyed by content, and the expression user by user. The ⋯ menu's stable callbacks read the latest onToggleFavorite, t and address from a ref updated after every commit. Nothing the sidebar shows or does changes; the changeset says so.
  • Contract review. This file list has no contract face (record-recognisers --brief-template --paths exits 1 and decides none): no spec path, Clause-②: no, Metadata-protocol: none. The seat's ACCEPT at TIER_DEFAULT is the review of record.
  • Governance. check-governed-merges.mjs: not governed, 522 changed lines. Tier S.

Tier: S. Landing: ready + auto-merge by this stroke.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 27, 2026 00:23
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit ce4d8c7 Nov 27, 2026
57 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-xtck3b branch November 27, 2026 00:43
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
… the shell re-renders less during first load (objectstack-ai#37883)

Part of objectstack-ai#37575
Part of objectstack-ai#37444

This is slice 2 of the first-render card. It does not bring the list and
record pages under 2.5 s, so the card stays open. The section "What is
left" below says what still costs the time.

Clause-②: yes (narrowing)
Metadata-protocol: none
Skills-docs: none — no skill or doc page names `appContentLanguages`
(git grep of `skills/`, `content/` and `docs/`; only two changesets do)

**Narrowing (public API of `@object-ui/i18n` and `@object-ui/react`):**
`useObjectTranslation()` and `useI18nContext()` no longer return
`appContentLanguages`, which objectstack-ai#36040 added to them and which has shipped.
`@object-ui/react` re-exports both hooks, so the narrowing reaches that
entry too. Read the list with the new `useAppContentLanguages()`
instead; both entries export it. The changeset carries the BREAKING
section and an ADR-0087 disposition. It ships `patch` because the change
is not to the metadata protocol.

## 维护者速读

- 控制台用户打开列表页、记录页时,首屏少做几遍整块重绘,看到的内容和交互不变;同机对照列表页快约 80 毫秒、记录页快约 90
毫秒,首页不变。
- 属于「首屏打开速度」专题,接着上一片侧栏的改动,继续削减首屏前的重复渲染。
- 出错的话,最可能是列表行末按钮、侧栏入口的显隐、或语言菜单的「内容未翻译」提示显示不对;整个提交可以直接撤回。
- 无

## What changes

Between a list's rows' first render and their first paint the grid drew
the whole table three more times, and the shell re-rendered large parts
of the page for answers few components read. Each cut below removes one
such pass; none changes what is drawn.

**Grid (`@object-ui/plugin-grid`)**

1. `ObjectGrid`'s loading face now draws inside the same root element
the loaded table uses (same type, place and ref). React keeps the
element across the swap, so `gridRoot`, and the list page scope answer
read off it, is known when the rows first render. Before, the rows drew
once with row-end controls and the `_actions` column, the root's ref
then answered "list page", and the table drew again without them (plus a
right-shadow flip).
2. `useInlineRowActionFold` watches its host from a stable callback ref
instead of holding the element in state, so mounting the host no longer
re-renders `ObjectGrid` (an 838-component pass).
3. `useRecordCrudVerdicts` publishes a verdict map only when it differs
from the published one. It used to publish a new empty `Map` on every
read before anything was asked, which re-rendered the grid for nothing.

**Shell**

4. `@object-ui/i18n`: the app's own locale list (`appContentLanguages`)
moves to its own context, read with the new `useAppContentLanguages()`.
The list lands late in boot; in the main context it re-rendered every
`useObjectTranslation` reader (about 1,900 components on a list page).
`useObjectTranslation()` and `useI18nContext()` no longer carry the
field; its two readers (`LocaleSwitcher`, the profile page's language
card) use the new hook. `@object-ui/react` re-exports the new hook
beside the two it re-exports already (contract review S1). This removal
narrows the published API: it is declared `Clause-②: yes (narrowing)`
above and in the changeset, with a BREAKING section that names the
replacement hook and the reason (about 1,900 first-load components no
longer re-render when the list lands).
5. `@object-ui/layout`: the row memo from objectstack-ai#37722 also compares the
capability checker by what it answers for a leaf row (`requiresObject`,
`requiresService`), as it already did for the three target resolvers.

## Tests

Each pin fails on `main` and passes here; I checked this by running each
one against the `main` version of the source:

- `plugin-grid/src/__tests__/listGridFirstRender-37575.test.tsx`: a list
page grid never puts a row-end control in the DOM, not even for one
commit (a MutationObserver reads added and removed nodes); attaching the
fold's host renders nothing; re-reading verdicts with nothing answered
keeps the same lookup.
- `i18n/src/__tests__/provider-appContentLanguages-37575.test.tsx`: a
memoised translation reader is not re-rendered when the list lands; a
reader of the list is.
- `layout/src/__tests__/NavigationRenderer.rowMemo-37575.test.tsx`: a
new capability checker with the same answers redraws no leaf row, and
one that hides a row removes it.

Two list tests changed. `plugin-list` `ListView.harness` (objectui#6917
block) and `app-shell` `ObjectView.titleViewSwitcher-27594` read the
record-count bar, which a grid does not draw: the grid draws the count
in its resident footer row (`data-table-summary-lead`,
objectstack#35702), and ListView hides the bar once the grid says so.
The tests caught the bar in the frames before that, frames the grid no
longer spends. They now read the grid's footer count. The expected
numbers are unchanged, and both pass on `main` too.

**Taken back out (head 6049056):** a first version mounted each sidebar
row's Radix tooltip only in the icon rail, which saved about 750 mounts.
Folding or docking the sidebar then swapped the row's wrapper, so its
button remounted and keyboard focus was lost
(`UnifiedSidebar.railOverlay-27593`,
`UnifiedSidebar.hiddenCollapse-35062` caught it). The primitive under
`components/src/ui` is not edited here, so that cut needs its own
design.

## Acceptance notes

<details><summary>Readings: Lighthouse 13.6.0 desktop, HTTP/2 TLS front,
10 runs per page, the objectstack-ai#37444 method; base and PR built and measured in
the same session, back to back</summary>

Production console build served by `objectstack start`
(`NODE_ENV=production`) behind the local h2 front, signed in, cold
cache, 4-core container.

| Page | `main` 1028438 (median of 10) | this PR at 6049056 (median of
10) | Δ |
|:--|--:|--:|--:|
| Home | 2207 | 2214 | +7 (noise) |
| Object list | 2768 | 2685 | −83 |
| Record page | 2594 | 2504 | −90 |

Sorted runs: main home 2130…2289, list 2583…2964, record 2494…2883; PR
home 2143…2371, list 2516…2835, record 2417…2676.

The machine read about 90 ms slower than the readings at session start
(main list 2662 then, 2755 now), which is why both columns come from the
same hour.

React commit census, list page, on the build that still had the tooltip
cut: components re-rendered before the rows mount went from about 10,300
to about 6,000. Without that cut the mounts stay as on `main`. Between
the rows' DOM insertion and the first paint after it there is no commit
any more (Performance observer + commit hook timestamps).
</details>

<details><summary>What is left: why the list and record pages are still
over 2.5 s</summary>

- Lighthouse's main-thread breakdown on the list page is about 2.0 s of
script evaluation, almost all of it React render work attributed to
`vendor-react`. The main thread is busy from about 600 ms to the paint.
- Of what this PR leaves before the rows, the passes are mostly real
content arriving: translation bundles (the `t` identity), object labels
as the metadata store fills (`MetadataProvider`'s global `version`
counter re-renders every metadata reader on each bump, 6 bumps on a list
page), the app menu. Cutting those needs a selector-style metadata
store, not a memo. That is an L-size change in `app-shell`, the next
lever for this card.
- Each row's ⋯ menu still mounts a Radix `DropdownMenu`, whose Popper
anchor re-renders its trigger once (a ~460 component pass). Mounting the
menu on first pointer or focus would remove it.
- After the rows mount, 4 passes remain after the first paint and do not
delay LCP: the view bar (`ManageViewsDialog`'s view-id array), the
table's right shadow (measured in a layout effect), the object schema
arriving, and the columns reseed.
</details>

## Verification

Read first, by risk:
1. `ui/packages/plugin-grid/src/ObjectGrid.tsx`, the loading branch: the
root element must stay the same type, place and ref as the final return,
or the fix silently stops working (the MutationObserver pin catches
that).
2. `ui/packages/layout/src/NavigationRenderer.tsx`, `sameRowAnswers`:
the capability checker is compared by answers for leaf rows.
3. `ui/packages/i18n/src/provider.tsx`: the new context and
`useAppContentLanguages()`.

Two-minute check: `pnpm --dir ui exec vitest run
packages/plugin-grid/src/__tests__/listGridFirstRender-37575.test.tsx
packages/i18n/src/__tests__/provider-appContentLanguages-37575.test.tsx
packages/layout/src/__tests__/NavigationRenderer.rowMemo-37575.test.tsx`.
All the tests should pass.

Local runs: the `plugin-grid` package (317 files, 2,794 tests),
`layout`, `i18n`, the console's `pages/system` tests and the
`LocaleSwitcher` tests all pass. Type checks pass for `i18n`, `layout`,
`plugin-grid`, `app-shell` and the console. `eslint` on the changed
files reports 0 errors. All 39 `dispatch-gates --commands` pass. One of
them, `vitest run scripts/`, was killed for memory in the batch run, and
I re-ran it on its own with 2 workers: 172 files passed.

## Human Minimum

- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01L6bhgTd1y1ncyDVcgVtep5

<!-- signed: repo:objectstack#2 · os-sales ·
session_01L6bhgTd1y1ncyDVcgVtep5 -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants