Skip to content

Commit 3eb778d

Browse files
perf(console): a list page draws its rows once before they paint, and the shell re-renders less during first load (#37883)
Part of #37575 Part of #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 #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 #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 #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>
1 parent 43ce731 commit 3eb778d

21 files changed

Lines changed: 367 additions & 67 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
'@object-ui/i18n': patch
4+
'@object-ui/react': patch
5+
'@object-ui/layout': patch
6+
'@object-ui/app-shell': patch
7+
'@object-ui/console': patch
8+
'@objectstack/console': patch
9+
---
10+
11+
perf(console): a list page draws its rows once before they paint, and the shell re-renders less during first load
12+
13+
Clause-②: yes (narrowing)
14+
Metadata-protocol: none
15+
16+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value, metadata type or stored row is added, removed or renamed, so there is nothing for `objectstack migrate meta` to rewrite. What narrows is the value two React hooks of @object-ui/i18n return: `useObjectTranslation()` and `useI18nContext()` no longer carry `appContentLanguages`, which moved to its own hook. Its consumer is code, and the compiler names every reader left behind. `runtime-interface-only` does not fit on a checked fact: the context value's interface is not exported, so it cannot be named by path. -->
17+
18+
On a list page's first load the grid drew its whole table several times between the rows' first render and their first paint: once with row-end controls before the list page scope was known, once when the inline-action fold found its host, and once when the record verdicts were republished with nothing new in them. The rows now draw once, without row-end controls, and those passes are gone.
19+
20+
The shell does less during first load too. The app's own locale list lands after the console has drawn; it used to re-render every component that reads a translation, about 1,900 of them. It is now read with `useAppContentLanguages()` from `@object-ui/i18n`, and only the language menus re-render for it. `useObjectTranslation()` and `useI18nContext()` no longer carry `appContentLanguages`. A sidebar entry is not redrawn when a new capability checker gives it the same answer.
21+
22+
Nothing changes in what the list, the sidebar or the language menus show.
23+
24+
**BREAKING** (`@object-ui/i18n`, and `@object-ui/react`, which re-exports the same two hooks: their return values), shipped as `patch`: the change is not to the metadata protocol (`Metadata-protocol: none`).
25+
26+
- Removed: the `appContentLanguages` field from what `useObjectTranslation()` and `useI18nContext()` return, whether they are imported from `@object-ui/i18n` or from `@object-ui/react`. It was added there by #36040.
27+
- Use instead: `useAppContentLanguages()`, which both entries now export: `@object-ui/i18n`, and `@object-ui/react` beside the two hooks. It returns the same value, the app's declared content languages or `null` while they are unknown, and `null` outside an `I18nProvider`.
28+
- Why: the list lands after the console has drawn. While it rode on the translation context, its arrival re-rendered every component that reads a translation, about 1,900 of them on first load. In its own context only the components that read it re-render.

‎ui/apps/console/src/pages/system/ProfilePage.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
import { useUpload } from '@object-ui/fields';
3939
import { toast } from 'sonner';
4040
import { ConsolePageHeader } from '@object-ui/app-shell';
41-
import { resolveBuiltInLanguage, useDisplayLocale, useObjectTranslation, type TranslateFn } from '@object-ui/i18n';
41+
import { resolveBuiltInLanguage, useAppContentLanguages, useDisplayLocale, useObjectTranslation, type TranslateFn } from '@object-ui/i18n';
4242
import { useAdapter, extractFieldErrors, extractWriteErrorMessage } from '@object-ui/react';
4343
import { usePermissions } from '@object-ui/permissions';
4444
import { resolveFieldAffordance } from '@object-ui/core';
@@ -589,7 +589,7 @@ interface LanguageCardProps {
589589
* (every platform locale table language, as table tags, objectstack#35425),
590590
* which is what `LocaleSwitcher` renders too. ⛔ No second list is introduced here.
591591
* A chosen language the deployment's own content is not translated into
592-
* (outside the provider's `appContentLanguages`, when that is known) carries
592+
* (outside `useAppContentLanguages()`, when that is known) carries
593593
* the same one-line hint the globe menu shows on that row.
594594
* A stored tag that is not in that set is prepended so the control shows the
595595
* truth rather than rendering blank.
@@ -606,7 +606,8 @@ interface LanguageCardProps {
606606
* card's own "hidden ... rather than rendering a control that answers 403".
607607
*/
608608
function LanguageCard({ userId }: LanguageCardProps) {
609-
const { t, offerableLanguages, appContentLanguages } = useObjectTranslation();
609+
const { t, offerableLanguages } = useObjectTranslation();
610+
const appContentLanguages = useAppContentLanguages();
610611
const adapter = useAdapter();
611612
const perms = usePermissions();
612613

‎ui/apps/console/src/pages/system/__tests__/ProfilePage.access.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ vi.mock('@object-ui/fields', async (importOriginal) => ({
5050

5151
vi.mock('@object-ui/i18n', async (importOriginal) => ({
5252
...(await importOriginal<Record<string, unknown>>()),
53-
useObjectTranslation: () => ({ t: translate, offerableLanguages: ['en', 'zh'], appContentLanguages: null }),
53+
useObjectTranslation: () => ({ t: translate, offerableLanguages: ['en', 'zh'] }),
5454
}));
5555

5656
vi.mock('@object-ui/react', async (importOriginal) => ({

‎ui/apps/console/src/pages/system/__tests__/ProfilePage.appLock-29748.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ vi.mock('@object-ui/fields', async (importOriginal) => ({
5454

5555
vi.mock('@object-ui/i18n', async (importOriginal) => ({
5656
...(await importOriginal<Record<string, unknown>>()),
57-
useObjectTranslation: () => ({ t: translate, language: 'en', offerableLanguages: ['en'], appContentLanguages: null }),
57+
useObjectTranslation: () => ({ t: translate, language: 'en', offerableLanguages: ['en'] }),
5858
}));
5959

6060
vi.mock('@object-ui/react', async (importOriginal) => ({

‎ui/apps/console/src/pages/system/__tests__/ProfilePage.language.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({
102102
String(options?.[name] ?? ''),
103103
),
104104
offerableLanguages: offerable.value,
105-
appContentLanguages: appContent.value,
106105
}),
106+
useAppContentLanguages: () => appContent.value,
107107
}));
108108

109109
/**

‎ui/apps/console/src/pages/system/__tests__/ProfilePage.pageHeader-12553.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ vi.mock('@object-ui/fields', async (importOriginal) => ({
4949
/** Each call site's key, so the pin names the pack key it reads. */
5050
vi.mock('@object-ui/i18n', async (importOriginal) => ({
5151
...(await importOriginal<Record<string, unknown>>()),
52-
useObjectTranslation: () => ({ t: (key: string) => `«${key}»`, offerableLanguages: ['en'], appContentLanguages: null }),
52+
useObjectTranslation: () => ({ t: (key: string) => `«${key}»`, offerableLanguages: ['en'] }),
5353
}));
5454

5555
vi.mock('@object-ui/react', async (importOriginal) => ({

‎ui/apps/console/src/pages/system/__tests__/ProfilePage.sharedSelect-11865.test.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({
6666
useObjectTranslation: () => ({
6767
t: (key: string, options?: Record<string, unknown>) => String(options?.defaultValue ?? key),
6868
offerableLanguages: offerable.value,
69-
appContentLanguages: null,
7069
}),
7170
}));
7271

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* (objectstack#35425, which reversed the narrowing to the app's own locale
1111
* list). A language the app's own content is not translated into stays
1212
* selectable and carries one muted line saying that content shows in the
13-
* default language; the provider's `appContentLanguages` says which those are,
13+
* default language; `useAppContentLanguages()` says which those are,
1414
* and a page that does not know (signed out) marks none. This file owns the
1515
* *labels* and that hint, because the native
1616
* names are the one piece of that no API response supplies:
@@ -34,7 +34,7 @@ import {
3434
DropdownMenuItem,
3535
DropdownMenuTrigger,
3636
} from '@object-ui/components';
37-
import { resolveBuiltInLanguage, useObjectTranslation } from '@object-ui/i18n';
37+
import { resolveBuiltInLanguage, useAppContentLanguages, useObjectTranslation } from '@object-ui/i18n';
3838
import { PLATFORM_LOCALES } from '@objectstack/spec/system';
3939
import { confirmUnsavedLeave } from '../chrome/unsavedEdits.js';
4040
import { useLanguageSelection } from '../hooks/useUserLocale.js';
@@ -82,7 +82,8 @@ export function localeLabel(code: string): string {
8282
}
8383

8484
export function LocaleSwitcher() {
85-
const { t, language, offerableLanguages, appContentLanguages } = useObjectTranslation();
85+
const { t, language, offerableLanguages } = useObjectTranslation();
86+
const appContentLanguages = useAppContentLanguages();
8687
// ⛔ Not the i18n context's bare `changeLanguage`: while signed in the switch
8788
// has to reach `sys_user.locale`, or the globe and the profile page go on
8889
// naming two settings (objectui#10059). Signed out it IS the bare switch.

‎ui/packages/app-shell/src/views/ObjectView.titleViewSwitcher-27594.test.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,16 @@ function openSwitcher() {
166166
return screen.getByTestId('list-view-switcher-menu');
167167
}
168168

169-
/** The list's footer once its load settled: it says how many records the view holds. */
169+
/**
170+
* The list's footer count once its load settled: it says how many records the
171+
* view holds. A grid draws it in its resident footer row
172+
* (`data-table-summary-lead`, objectstack#35702) and the record-count bar then
173+
* not at all; any other view draws it in the bar.
174+
*/
175+
const FOOTER_COUNT = '[data-testid="data-table-summary-lead"], [data-testid="record-count-bar"]';
176+
const footerCountElement = () => document.querySelector<HTMLElement>(FOOTER_COUNT);
170177
const footerCount = () =>
171-
waitFor(() => expect(screen.getByTestId('record-count-bar')).toHaveTextContent('1 record'), { timeout: 5000 });
178+
waitFor(() => expect(footerCountElement()).toHaveTextContent('1 record'), { timeout: 5000 });
172179

173180
/** The ids of the rows in the dropdown's All section, in order. */
174181
const allRowIds = () =>
@@ -308,7 +315,7 @@ describe('objectstack#27594 — the list title is the view switcher', () => {
308315
// phone as it was).
309316
await footerCount();
310317
expect(screen.getByTestId('list-view-switcher-count')).toHaveClass('max-sm:hidden');
311-
expect(screen.getByTestId('list-toolbar-leading').contains(screen.getByTestId('record-count-bar'))).toBe(false);
318+
expect(screen.getByTestId('list-toolbar-leading').contains(footerCountElement())).toBe(false);
312319
expect(screen.queryByTestId('view-tab-bar')).toBeNull();
313320
expect(screen.queryByTestId('view-tab-row')).toBeNull();
314321

‎ui/packages/i18n/src/__tests__/provider-app-locale-restore.test.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import { describe, it, expect, beforeEach } from 'vitest';
3131
import { renderHook, act, waitFor } from '@testing-library/react';
3232
import React from 'react';
3333
import { PLATFORM_LOCALE_TAGS } from '@objectstack/spec/system';
34-
import { I18nProvider, useObjectTranslation, LOCALE_STORAGE_KEY } from '../provider';
34+
import { I18nProvider, useAppContentLanguages, useObjectTranslation, LOCALE_STORAGE_KEY } from '../provider';
35+
36+
/** The translation hook and the app-content answer, read together. */
37+
const useReaders = () => ({ ...useObjectTranslation(), appContentLanguages: useAppContentLanguages() });
3538

3639
/** The console's wiring: app packs fetched on demand, nothing in `resources`. */
3740
function mountConsole(
@@ -46,7 +49,7 @@ function mountConsole(
4649
...props,
4750
children,
4851
});
49-
return renderHook(() => useObjectTranslation(), { wrapper });
52+
return renderHook(() => useReaders(), { wrapper });
5053
}
5154

5255
beforeEach(() => {
@@ -178,7 +181,7 @@ describe('app-locale restore (lockstep with the switcher)', () => {
178181
config: { defaultLanguage: 'en', detectBrowserLanguage: false },
179182
children,
180183
});
181-
const { result } = renderHook(() => useObjectTranslation(), { wrapper });
184+
const { result } = renderHook(() => useReaders(), { wrapper });
182185

183186
// Nothing can fetch `th` here, so accepting it would be the very "locked to
184187
// a locale with no translations" state the guard exists to prevent. The
@@ -272,7 +275,7 @@ describe('appContentLanguages — the table languages the app list covers', () =
272275
loadLocales: async () => ['en', 'zh', 'th'],
273276
children,
274277
});
275-
const { result } = renderHook(() => useObjectTranslation(), { wrapper });
278+
const { result } = renderHook(() => useReaders(), { wrapper });
276279

277280
await waitFor(() => expect(result.current.appContentLanguages).toEqual(['en', 'zh-Hans']));
278281
});
@@ -297,7 +300,7 @@ describe('appContentLanguages — the table languages the app list covers', () =
297300
children,
298301
}),
299302
);
300-
const { result, rerender } = renderHook(() => useObjectTranslation(), { wrapper });
303+
const { result, rerender } = renderHook(() => useReaders(), { wrapper });
301304

302305
await waitFor(() => expect(result.current.appContentLanguages).toEqual(['en', 'zh-Hans']));
303306
rerender();

0 commit comments

Comments
 (0)