Repository navigation
perf(console): the sidebar no longer redraws every entry each time the console re-renders during first load - #37722
Merged
Conversation
…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>
Contributor
Author
|
repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA 席位核对 — ACCEPT · head 1be3a93 · cards #37444 / #37575 · area s2-ux · 2026-11-27T00:22ZL1 checklist
Tier: S. Landing: ready + auto-merge by this stroke. |
This was referenced Nov 27, 2026
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>
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.
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
维护者速读
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 inReact.memowith 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 namedNavItemRendererProps.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 ontogglePinandactiveApp.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, stabletoggleFavorite/copyLink) and a memoisedSidebarItemMenuViewthat 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 emptydatais a module constant. Rebuilding both on every render gaveExpressionProvidera new value each pass, which alone made every visibility-gated entry redraw.No behaviour, string, route or saved document changes. Changeset:
patchon@object-ui/layout,@object-ui/app-shell,@object-ui/console,@objectstack/console(the Console dist ships the change).Tests
ui/packages/layout/src/__tests__/NavigationRenderer.rowMemo-37575.test.tsx(5 tests) countsrenderItemActioncalls 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 newevaluateVisibilityredraws every row. Ablation: without the memo, 4 of 5 fail; with a plainReact.memo(no comparator), 3 of 5 fail.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/layoutand@object-ui/app-shelltests (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 --noEmitexit 0 inui/packages/layoutandui/packages/app-shell, for bothtsconfig.jsonandtsconfig.test.json.eslintover the changedui/files: 0 errors. One advisory React-compiler warning remains inUnifiedSidebar.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:buildat this head),objectstack startwithNODE_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:9476092c)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:
sameRowAnswersinNavigationRenderer.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 inSidebarItemMenu.tsx.Local gates (derived by dispatch-gates.mjs --commands at the final head)
Head
1be3a932(the gates ran atbc00135f, 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 0node scripts/check-adr-0087-registration.mjs --self-test→ exit 0node scripts/check-changeset-no-major.mjs --base origin/main→ exit 0node scripts/check-closing-keyword-parity.mjs→ exit 0node scripts/check-closing-keyword-parity.mjs --self-test→ exit 0node scripts/check-comment-mask-corpus.mjs→ exit 0node scripts/check-empty-changeset.mjs --base origin/main→ exit 0node scripts/check-empty-changeset.mjs --self-test→ exit 0node scripts/check-sdui-manifest.mjs→ exit 0node scripts/check-sdui-manifest.mjs --self-test→ exit 0node scripts/ci/snapshot-next.mjs --self-test→ exit 0node scripts/pm/check-governed-queue-guard.mjs --self-test→ exit 0node scripts/pm/release-rehearsal-clone.mjs --self-test→ exit 0node scripts/release-pending-publish.mjs --self-test→ exit 0pnpm --dir ui exec vitest run scripts/→ exit 0pnpm --filter @objectstack/spec run check:duration-unit-keys→ exit 0pnpm check:adr-anchors→ exit 0pnpm check:changeset-gate-self-tests→ exit 0pnpm check:closed-ceremony-text→ exit 0pnpm check:cross-package-test-inputs→ exit 0pnpm check:dispatcher-error-vocabulary→ exit 0pnpm check:driver-memory-census→ exit 0pnpm check:engine-double-contract→ exit 0pnpm check:gitlink-declared→ exit 0pnpm check:nul-bytes→ exit 0pnpm check:published-files→ exit 0pnpm check:query-options-erasure→ exit 0pnpm check:refd-timer-probe→ exit 0pnpm check:registry-log-declared→ exit 0pnpm check:rest-log-spy-declared→ exit 0pnpm check:skill-identifier-liveness→ exit 0pnpm check:test-source-alias→ exit 0pnpm check:tier-file-adoption→ exit 0pnpm check:type-check-coverage→ exit 0pnpm check:type-check-debt→ exit 0pnpm check:undeclared-dep-imports→ exit 0pnpm check:watch-hint-literal→ exit 0pnpm check:where-matcher→ exit 0Human Minimum
packages/specholds no runtime logic.pnpm lintpasses.main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (not touched)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01L6bhgU8Bf564ZGXi4MfHWb
Generated by Claude Code