Skip to content

Commit 04ca403

Browse files
perf(app-shell): the form list's words load with the Studio list, not at boot (#38682)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ844kETyNGBBt9atKc1Snfzd)_ Part of #37444 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:看不到界面变化。打开 Console 的每一页时,首屏不再提前下载 Studio 的翻译包(约 82 KiB);表单列表的「开/关」文字在打开 Studio 列表时才加载。 - 为什么做:#38484 之后,表单列表的列定义在启动时就静态引入了 Studio 翻译模块,把 #38429 已经挪出首屏的翻译包又带了回来(#37444 的固定对照测量发现,评论 7264938326)。 - 效果:首屏少下载 82 KiB;但复测对象列表 LCP 只快 15 ms(p 0.54,误差内),仍比 2500 ms 超约 68 ms。所以本 PR 修掉回退,不关卡;列表剩下的差距在渲染 CPU,归 #37575。 - 出错会怎样:最坏是表单列表「开/关」一栏首次显示时晚一帧;可直接撤回。 - 要你做的:无。发布冻结期保持 draft。 ## What changes - `ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx` no longer imports `../../metadata-admin/i18n.js` statically. The form list's On cell loads the designer string table with `React.lazy` on first draw; the Studio list has already loaded that module by then, so it resolves at once. - `services/builtinComponents.tsx` still registers `FORM_LIST_COLUMNS` at boot, but the boot closure no longer reaches the metadata-admin i18n module, so the built Console's `index.html` no longer preloads `i18n-ns-studio-en` (70.8 KiB) or the metadata-admin i18n chunk (10.3 KiB): 134 modulepreloads, list 229 → 225 scripts before LCP. - Pin: `ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx` — (1) the walk sees the edge it guards (ResourceListPage reaches the designer table); (2) `builtinComponents.tsx` reaches no designer table through static imports; (3) the On cell renders "On"/"Off" after the lazy load. - Changeset: patch, `@object-ui/app-shell`. ## Tests Head `e1bbe0b8` (reworded to `394a0455` for the commit-trailer check; identical tree): - Under the lock: the new pin plus `studio-design/publicForm` and `firstScreenStudioCatalogue-37444`: 4 files, 54/54 passed; `ui scripts/__tests__/check-i18n-call-site-keys.test.ts`: 152/152 passed. - Ablation (`scripts/ablation-replace.mjs`): a static `import { t } from '../../metadata-admin/i18n.js'` put back into `formListColumns.tsx` turns case 2 red (1 failed, 2 passed); restored, blob == HEAD. - `pnpm --filter @object-ui/app-shell type-check`: exit 0. `pnpm console:build`: exit 0; `index.html` has no `i18n-ns-studio` or metadata-admin i18n chunk. - Browser, branch production build: `/_console/studio/~all/metadata/form` shows "On" for `showcase_inquiry.contact` and `showcase_inquiry.feedback`. ## Measurement (production build, HTTP/2, Lighthouse desktop, ruling conditions) One session, arms branch / base `f5da514b` / control `1afd9c13`, 20 runs per arm per page; control list 2535.1 ms, inside the pre-set band, so scored; no block discarded. | page | branch | base | branch − base | |:--|--:|--:|--:| | object list | 2568.4 | 2583.4 | −15.0 ms (p 0.54, 95% CI −60…+71) | | record | 2446.9 | 2434.3 | +12.7 ms (p 0.81) | The cut restores the bytes but has no measurable LCP effect; the done-when stays unmet on the list. Readings and instrument: project folder `card-37444/a-measure/recut/`; report comment 7266607998 on #37444. ## Verification - `dispatch-gates --commands`: 38 derived, 38 run, all exit 0 (`ui scripts/` vitest re-run with `--maxWorkers=2` after an OOM kill while measurement servers were up: 172 passed, 2 skipped). `--ran`: 0 NOT-MEASURED. - `overlap-check.mjs`: clean against origin/main; `git merge-tree` against origin/main at push: clean. - CI check-runs: read on this PR. Files to read first: `formListColumns.tsx` (the lazy On cell). Two-minute check: open Studio → Forms list; the On column reads "On"/"Off". 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbamiNxp7695qyaEYsH <!-- signed: repo:objectstack#2 · os-warren · session_01JQwxbamiNxp7695qyaEYsH --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1d959b0 commit 04ca403

3 files changed

Lines changed: 135 additions & 3 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@objectstack/console': patch
4+
---
5+
6+
perf(app-shell): every Console page stops loading the Studio designer's English strings before its first screen
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Since the Studio forms list gained its "On" column, every Console page fetched the Studio designer's string table (about 81 KB gzip in two files) before its first screen, though only that list shows the words. The column's words now load the first time the column draws. By then the Studio list has already loaded the same strings, so they show at once.
12+
13+
Nothing a user sees or saves changes. Nothing to migrate.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#37444 — the boot registrations do not carry the Studio
5+
* designer's string table onto every page's first load.
6+
*
7+
* `services/builtinComponents.tsx` runs at boot: it registers the `form`
8+
* metadata list with `FORM_LIST_COLUMNS`. When `formListColumns.tsx` imported
9+
* the designer's `t()` (`metadata-admin/i18n.ts`) statically, the Console's
10+
* `index.html` preloaded that module and the `studio` namespace's English
11+
* catalogue on home, list and record pages alike (about 81 KiB, measured on
12+
* the Console build of `0ba5e06ae7` against `1afd9c13`). The "On" cell now
13+
* loads its words with `import()` on first render.
14+
*
15+
* The walk follows each module's STATIC relative imports in source (type-only
16+
* imports and `import()` excluded, as the browser loads them) and asserts the
17+
* boot module never reaches the designer's string table. It is checked to see
18+
* the edge it guards: the Studio list module itself must reach it.
19+
*/
20+
import { readFileSync, existsSync } from 'node:fs';
21+
import { dirname, resolve } from 'node:path';
22+
import { fileURLToPath } from 'node:url';
23+
import * as React from 'react';
24+
import { render, screen } from '@testing-library/react';
25+
import { describe, expect, it } from 'vitest';
26+
import { FORM_LIST_COLUMNS } from '../../views/studio-design/publicForm/formListColumns.js';
27+
28+
const SRC = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
29+
const DESIGNER_I18N_FILE = resolve(SRC, 'views/metadata-admin/i18n.ts');
30+
const DESIGNER_I18N_SPECIFIER = /^@object-ui\/i18n\/namespaces\/studio$/;
31+
32+
/** Static value imports of one module: `import … from '…'`, `import '…'` and `export … from '…'`, never `import type`. */
33+
function staticSpecifiers(code: string): string[] {
34+
const out: string[] = [];
35+
const re = /^\s*(import|export)\s+(?!type\s)([^;]*?\bfrom\s+)?['"]([^'"]+)['"]/gm;
36+
for (const m of code.matchAll(re)) {
37+
if (m[1] === 'export' && !m[2]) continue;
38+
out.push(m[3]);
39+
}
40+
return out;
41+
}
42+
43+
function resolveRelative(from: string, specifier: string): string | null {
44+
const base = resolve(dirname(from), specifier.replace(/\.js$/, ''));
45+
for (const candidate of [`${base}.ts`, `${base}.tsx`, resolve(base, 'index.ts'), resolve(base, 'index.tsx')]) {
46+
if (existsSync(candidate)) return candidate;
47+
}
48+
return null;
49+
}
50+
51+
/** The first chain from `entry` to the designer string table, or `null`. */
52+
function chainToDesignerI18n(entry: string): string[] | null {
53+
const start = resolve(SRC, entry);
54+
const prev = new Map<string, string | null>([[start, null]]);
55+
const queue = [start];
56+
const chainTo = (at: string | null, tail: string[] = []) => {
57+
const chain = [...tail];
58+
for (; at; at = prev.get(at) ?? null) chain.unshift(at.slice(SRC.length + 1));
59+
return chain;
60+
};
61+
while (queue.length) {
62+
const file = queue.shift() as string;
63+
for (const specifier of staticSpecifiers(readFileSync(file, 'utf8'))) {
64+
if (DESIGNER_I18N_SPECIFIER.test(specifier)) return chainTo(file, [specifier]);
65+
if (!specifier.startsWith('.')) continue;
66+
const next = resolveRelative(file, specifier);
67+
if (!next || prev.has(next)) continue;
68+
prev.set(next, file);
69+
if (next === DESIGNER_I18N_FILE) return chainTo(next);
70+
queue.push(next);
71+
}
72+
}
73+
return null;
74+
}
75+
76+
describe('the boot registrations carry no Studio designer string table (objectstack#37444)', () => {
77+
it('the walk sees the edge it guards: the Studio resource list reaches the designer table', () => {
78+
expect(chainToDesignerI18n('views/metadata-admin/ResourceListPage.tsx')).not.toBeNull();
79+
});
80+
81+
it('services/builtinComponents.tsx reaches no designer string table through static imports', () => {
82+
expect(chainToDesignerI18n('services/builtinComponents.tsx')).toBeNull();
83+
});
84+
85+
it('the form list "On" cell still shows its translated words once rendered', { timeout: 20000 }, async () => {
86+
const column = FORM_LIST_COLUMNS.find((c) => c.key === 'publicState');
87+
const on = { name: 'intake', sharing: { enabled: true, allowAnonymous: true, publicLink: 'intake' } };
88+
const off = { name: 'draft', sharing: { enabled: false, publicLink: 'draft' } };
89+
// The Studio list loads the designer's strings before it draws this column.
90+
await import('../../views/metadata-admin/i18n.js');
91+
render(
92+
<div>
93+
{column?.render?.(undefined, on) as React.ReactNode}
94+
{column?.render?.(undefined, off) as React.ReactNode}
95+
</div>,
96+
);
97+
expect(await screen.findByText('On', undefined, { timeout: 10000 })).toBeTruthy();
98+
expect(await screen.findByText('Off', undefined, { timeout: 10000 })).toBeTruthy();
99+
expect(screen.getByTestId('form-list-state-intake').getAttribute('data-on')).toBe('true');
100+
expect(screen.getByTestId('form-list-state-draft').getAttribute('data-on')).toBe('false');
101+
});
102+
});

‎ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
* - "On" is the served `sharing` opening the form to anonymous intake
1313
* (`anonymousFormIntakeSlug`), the rule both anonymous doors apply. A form
1414
* with no public address shows none and is neither on nor off.
15+
*
16+
* This module is imported at boot (`services/builtinComponents.tsx` registers
17+
* the `form` list with these columns), so it holds no static import of the
18+
* designer's `t()` (`metadata-admin/i18n.ts`): that would put the Studio
19+
* string table on every page's first load. The "On" cell's words load with
20+
* `import()` on first render; by then the Studio list has loaded the same
21+
* module, so the import resolves at once.
1522
*/
1623

1724
import * as React from 'react';
1825
import { anonymousFormIntakeSlug, publicFormSlug } from '@objectstack/spec/ui';
19-
import { t, useMetadataLocale } from '../../metadata-admin/i18n.js';
2026
import type { MetadataResourceConfig } from '../../metadata-admin/registry.js';
2127

2228
type Row = Record<string, unknown>;
@@ -36,13 +42,24 @@ export function formListState(item: Row): 'on' | 'off' | null {
3642
return anonymousFormIntakeSlug(item.sharing) !== null ? 'on' : 'off';
3743
}
3844

45+
/** The cell's words, in the designer's locale; loaded on first render, not at boot. */
46+
const FormStateWord = React.lazy(() =>
47+
import('../../metadata-admin/i18n.js').then((designer) => ({
48+
default: function FormStateWord({ state }: { state: 'on' | 'off' }): React.ReactElement {
49+
const locale = designer.useMetadataLocale();
50+
return <>{designer.t(state === 'on' ? 'engine.studio.publicForms.stateOn' : 'engine.studio.publicForms.stateOff', locale)}</>;
51+
},
52+
})),
53+
);
54+
3955
function FormStateCell({ item }: { item: Row }): React.ReactElement {
40-
const locale = useMetadataLocale();
4156
const state = formListState(item);
4257
if (state === null) return <span className="text-muted-foreground">—</span>;
4358
return (
4459
<span data-testid={`form-list-state-${String(item.name)}`} data-on={state === 'on' ? 'true' : 'false'}>
45-
{t(state === 'on' ? 'engine.studio.publicForms.stateOn' : 'engine.studio.publicForms.stateOff', locale)}
60+
<React.Suspense fallback={null}>
61+
<FormStateWord state={state} />
62+
</React.Suspense>
4663
</span>
4764
);
4865
}

0 commit comments

Comments
 (0)