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. 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..72bfc9b61da --- /dev/null +++ b/ui/packages/app-shell/src/services/__tests__/builtinComponents.formListWordsOffBoot-37444.test.tsx @@ -0,0 +1,102 @@ +// 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', { 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', 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'); + }); +}); 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..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 @@ -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((designer) => ({ + default: function FormStateWord({ state }: { state: 'on' | 'off' }): React.ReactElement { + const locale = designer.useMetadataLocale(); + return <>{designer.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)} + + + ); }