From ec53e04522ce0761740a652fc733313257ab0e15 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 00:07:43 +0000 Subject: [PATCH 1/4] perf(app-shell): the form list's On words load on first render, not at boot Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbamiNxp7695qyaEYsH --- ...onents.formListWordsOffBoot-37444.test.tsx | 100 ++++++++++++++++++ .../publicForm/formListColumns.tsx | 23 +++- 2 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx diff --git a/ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx b/ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx new file mode 100644 index 00000000000..e6778b7875c --- /dev/null +++ b/ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx @@ -0,0 +1,100 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#37444 — the boot registrations do not carry the Studio + * designer's string table onto every page's first load. + * + * `services/builtinComponents.tsx` runs at boot: it registers the `form` + * metadata list with `FORM_LIST_COLUMNS`. When `formListColumns.tsx` imported + * the designer's `t()` (`metadata-admin/i18n.ts`) statically, the Console's + * `index.html` preloaded that module and the `studio` namespace's English + * catalogue on home, list and record pages alike (about 81 KiB, measured on + * the Console build of `0ba5e06ae7` against `1afd9c13`). The "On" cell now + * loads its words with `import()` on first render. + * + * The walk follows each module's STATIC relative imports in source (type-only + * imports and `import()` excluded, as the browser loads them) and asserts the + * boot module never reaches the designer's string table. It is checked to see + * the edge it guards: the Studio list module itself must reach it. + */ +import { readFileSync, existsSync } from 'node:fs'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import * as React from 'react'; +import { render, screen } from '@testing-library/react'; +import { describe, expect, it } from 'vitest'; +import { FORM_LIST_COLUMNS } from '../../views/studio-design/publicForm/formListColumns.js'; + +const SRC = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); +const DESIGNER_I18N_FILE = resolve(SRC, 'views/metadata-admin/i18n.ts'); +const DESIGNER_I18N_SPECIFIER = /^@object-ui\/i18n\/namespaces\/studio$/; + +/** Static value imports of one module: `import … from '…'`, `import '…'` and `export … from '…'`, never `import type`. */ +function staticSpecifiers(code: string): string[] { + const out: string[] = []; + const re = /^\s*(import|export)\s+(?!type\s)([^;]*?\bfrom\s+)?['"]([^'"]+)['"]/gm; + for (const m of code.matchAll(re)) { + if (m[1] === 'export' && !m[2]) continue; + out.push(m[3]); + } + return out; +} + +function resolveRelative(from: string, specifier: string): string | null { + const base = resolve(dirname(from), specifier.replace(/\.js$/, '')); + for (const candidate of [`${base}.ts`, `${base}.tsx`, resolve(base, 'index.ts'), resolve(base, 'index.tsx')]) { + if (existsSync(candidate)) return candidate; + } + return null; +} + +/** The first chain from `entry` to the designer string table, or `null`. */ +function chainToDesignerI18n(entry: string): string[] | null { + const start = resolve(SRC, entry); + const prev = new Map([[start, null]]); + const queue = [start]; + const chainTo = (at: string | null, tail: string[] = []) => { + const chain = [...tail]; + for (; at; at = prev.get(at) ?? null) chain.unshift(at.slice(SRC.length + 1)); + return chain; + }; + while (queue.length) { + const file = queue.shift() as string; + for (const specifier of staticSpecifiers(readFileSync(file, 'utf8'))) { + if (DESIGNER_I18N_SPECIFIER.test(specifier)) return chainTo(file, [specifier]); + if (!specifier.startsWith('.')) continue; + const next = resolveRelative(file, specifier); + if (!next || prev.has(next)) continue; + prev.set(next, file); + if (next === DESIGNER_I18N_FILE) return chainTo(next); + queue.push(next); + } + } + return null; +} + +describe('the boot registrations carry no Studio designer string table (objectstack#37444)', () => { + it('the walk sees the edge it guards: the Studio resource list reaches the designer table', () => { + expect(chainToDesignerI18n('views/metadata-admin/ResourceListPage.tsx')).not.toBeNull(); + }); + + it('services/builtinComponents.tsx reaches no designer string table through static imports', () => { + expect(chainToDesignerI18n('services/builtinComponents.tsx')).toBeNull(); + }); + + it('the form list "On" cell still shows its translated words once rendered', async () => { + const column = FORM_LIST_COLUMNS.find((c) => c.key === 'publicState'); + const on = { name: 'intake', sharing: { enabled: true, allowAnonymous: true, publicLink: 'intake' } }; + const off = { name: 'draft', sharing: { enabled: false, publicLink: 'draft' } }; + render( +
+ {column?.render?.(undefined, on) as React.ReactNode} + {column?.render?.(undefined, off) as React.ReactNode} +
, + ); + expect(await screen.findByText('On')).toBeTruthy(); + expect(await screen.findByText('Off')).toBeTruthy(); + expect(screen.getByTestId('form-list-state-intake').getAttribute('data-on')).toBe('true'); + expect(screen.getByTestId('form-list-state-draft').getAttribute('data-on')).toBe('false'); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx b/ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx index a82e462bb04..abb71cedd15 100644 --- a/ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx +++ b/ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx @@ -12,11 +12,17 @@ * - "On" is the served `sharing` opening the form to anonymous intake * (`anonymousFormIntakeSlug`), the rule both anonymous doors apply. A form * with no public address shows none and is neither on nor off. + * + * This module is imported at boot (`services/builtinComponents.tsx` registers + * the `form` list with these columns), so it holds no static import of the + * designer's `t()` (`metadata-admin/i18n.ts`): that would put the Studio + * string table on every page's first load. The "On" cell's words load with + * `import()` on first render; by then the Studio list has loaded the same + * module, so the import resolves at once. */ import * as React from 'react'; import { anonymousFormIntakeSlug, publicFormSlug } from '@objectstack/spec/ui'; -import { t, useMetadataLocale } from '../../metadata-admin/i18n.js'; import type { MetadataResourceConfig } from '../../metadata-admin/registry.js'; type Row = Record; @@ -36,13 +42,24 @@ export function formListState(item: Row): 'on' | 'off' | null { return anonymousFormIntakeSlug(item.sharing) !== null ? 'on' : 'off'; } +/** The cell's words, in the designer's locale; loaded on first render, not at boot. */ +const FormStateWord = React.lazy(() => + import('../../metadata-admin/i18n.js').then(({ t, useMetadataLocale }) => ({ + default: function FormStateWord({ state }: { state: 'on' | 'off' }): React.ReactElement { + const locale = useMetadataLocale(); + return <>{t(state === 'on' ? 'engine.studio.publicForms.stateOn' : 'engine.studio.publicForms.stateOff', locale)}; + }, + })), +); + function FormStateCell({ item }: { item: Row }): React.ReactElement { - const locale = useMetadataLocale(); const state = formListState(item); if (state === null) return —; return ( - {t(state === 'on' ? 'engine.studio.publicForms.stateOn' : 'engine.studio.publicForms.stateOff', locale)} + + + ); } From a125d9ca91524ab7d330a8e8dcfcac2b4484dc06 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 00:08:04 +0000 Subject: [PATCH 2/4] chore(changeset): the form list's words off the first load Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbamiNxp7695qyaEYsH --- .changeset/37444-form-list-words-off-first-load.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .changeset/37444-form-list-words-off-first-load.md diff --git a/.changeset/37444-form-list-words-off-first-load.md b/.changeset/37444-form-list-words-off-first-load.md new file mode 100644 index 00000000000..e521c198789 --- /dev/null +++ b/.changeset/37444-form-list-words-off-first-load.md @@ -0,0 +1,13 @@ +--- +'@object-ui/app-shell': patch +'@objectstack/console': patch +--- + +perf(app-shell): every Console page stops loading the Studio designer's English strings before its first screen + +Clause-②: no +Metadata-protocol: none + +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. + +Nothing a user sees or saves changes. Nothing to migrate. From 5f89f619c32dd82537e309387a72e058ac0f7a91 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 00:14:54 +0000 Subject: [PATCH 3/4] test(app-shell): pin the boot closure off the designer string table (objectstack#37444) Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbamiNxp7695qyaEYsH --- .../builtinComponents.formListWordsOffBoot-37444.test.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx b/ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx index e6778b7875c..72bfc9b61da 100644 --- a/ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx +++ b/ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx @@ -82,18 +82,20 @@ describe('the boot registrations carry no Studio designer string table (objectst expect(chainToDesignerI18n('services/builtinComponents.tsx')).toBeNull(); }); - it('the form list "On" cell still shows its translated words once rendered', async () => { + it('the form list "On" cell still shows its translated words once rendered', { timeout: 20000 }, async () => { const column = FORM_LIST_COLUMNS.find((c) => c.key === 'publicState'); const on = { name: 'intake', sharing: { enabled: true, allowAnonymous: true, publicLink: 'intake' } }; const off = { name: 'draft', sharing: { enabled: false, publicLink: 'draft' } }; + // The Studio list loads the designer's strings before it draws this column. + await import('../../views/metadata-admin/i18n.js'); render(
{column?.render?.(undefined, on) as React.ReactNode} {column?.render?.(undefined, off) as React.ReactNode}
, ); - expect(await screen.findByText('On')).toBeTruthy(); - expect(await screen.findByText('Off')).toBeTruthy(); + expect(await screen.findByText('On', undefined, { timeout: 10000 })).toBeTruthy(); + expect(await screen.findByText('Off', undefined, { timeout: 10000 })).toBeTruthy(); expect(screen.getByTestId('form-list-state-intake').getAttribute('data-on')).toBe('true'); expect(screen.getByTestId('form-list-state-draft').getAttribute('data-on')).toBe('false'); }); From 394a0455e1ada94ae7831da42c9b0b6fd2f0ca8f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 01:28:43 +0000 Subject: [PATCH 4/4] fix(app-shell): call the deferred designer table through its module, as the i18n call-site check reads it Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbamiNxp7695qyaEYsH --- .../src/views/studio-design/publicForm/formListColumns.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx b/ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx index abb71cedd15..a24de4a7f29 100644 --- a/ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx +++ b/ui/packages/app-shell/src/views/studio-design/publicForm/formListColumns.tsx @@ -44,10 +44,10 @@ export function formListState(item: Row): 'on' | 'off' | null { /** The cell's words, in the designer's locale; loaded on first render, not at boot. */ const FormStateWord = React.lazy(() => - import('../../metadata-admin/i18n.js').then(({ t, useMetadataLocale }) => ({ + import('../../metadata-admin/i18n.js').then((designer) => ({ default: function FormStateWord({ state }: { state: 'on' | 'off' }): React.ReactElement { - const locale = useMetadataLocale(); - return <>{t(state === 'on' ? 'engine.studio.publicForms.stateOn' : 'engine.studio.publicForms.stateOff', locale)}; + const locale = designer.useMetadataLocale(); + return <>{designer.t(state === 'on' ? 'engine.studio.publicForms.stateOn' : 'engine.studio.publicForms.stateOff', locale)}; }, })), );