Repository navigation
Commit 0628e08
perf(fields): the line-item grid's body loads on first use, out of the console's eager chunk (#36417)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbUq2j5tRRVo3TVY3wcS1Fdg)_
repo:objectstack#7 · zhuangjianguo · session_01QsR2jV3scu6UYPb42n5okQ
Fixes #36102
Clause-②: yes (widening)
Metadata-protocol: none
Ruling-ref: 7063116595 on #36023 (option B, "a separate card follows to
take GridField out of the eager chunk, after which the ceiling can come
back down"); seat note 7064483594 on this card, on ruling 7063869131
(lower the ceiling and baseline by the bytes taken out, no more)
## 维护者速读
- 用户无感:控制台首次加载少下载约 6
KB(压缩后),明细表格改为第一次打开带明细的表单时才加载,新建与编辑发票时表格照常出现、输入不丢焦点。
- 这是上次为放行明细表格改动而临时抬高控制台首屏体积上限之后约定的后续工作,把那部分体积收回来。
-
出错时最坏:明细表格的代码要单独下载,如果连续两次下载失败,错误会交给表单的出错处理,整个带明细的表单(不只是明细表格)会换成出错提示;网络正常时只是第一次打开时明细区多停一会儿在「正在加载列」。整个改动可直接撤回。
- 要你做什么:无。
## What changes
The line-item grid's body (`GridField`, about 90 KB of source) sat in
the console's eager `ui-components` chunk. The package entry imported it
lazily but also exported it statically, so the lazy import did nothing.
It now loads the first time a grid is drawn, in a lazy `fields-grid`
chunk. No published export was removed or renamed.
- **`ui/packages/fields/src/widgets/GridField.ts`** (new, the published
face). It keeps the pure helpers (`evalArith`, `computeRow`,
`lookupAutofillPatch`, `columnHelpByField`, `UNTOUCHED_NEW_ROW`,
`isUntouchedNewRow` and the column types), which stay eager. It also
exports `GridField` and `LineItemsField` as a small lazy face with the
same props.
- Each mount decides once: a grid mounted after the body has loaded
renders it directly. A grid mounted before that renders it through
`Suspense`, with a busy placeholder (`grid-field-loading`).
- A load landing later therefore never remounts the body, and focus is
kept.
- New export: `preloadGridField()`. It starts the one shared load and
never rejects; a failed load is reported by the grid that needs it,
through the nearest error boundary.
- **`widgets/grid-field/GridFieldWidget.tsx`** is the body, moved from
`widgets/GridField.tsx` (git reads it as a rename, R081). Only
`loadGridFieldWidget`'s `import()` reaches it.
- **The record forms wait for it.**
- `MasterDetailForm` starts the load when it mounts. It draws a
collection's grid only once the body has settled; until then it shows
its existing "Loading columns…" copy. That holds on every path: derived
columns, columns authored in full, and authored-but-untyped columns
drawn while the derivation is in flight.
- The record page's line-item editor (`RecordBodyTableEditor`) waits for
the body together with the child schema.
- `LineItemsPanel` starts the load when it mounts.
- **Console chunking:**
- `vite.config.ts` gains a `fields-grid` group (priority 82, ahead of
`ui-components`).
- `check-eager-closure-budget.mjs` gains its
`PER_CHUNK_MEMBERSHIP_CARVE_OUTS` row (`src/widgets/grid-field` →
`fields-grid`), following the `fields-date-picker` precedent
(objectui#12622).
- `vite-ineffective-dynamic-imports.ts` drops GridField from its
defeated-lazy list, because the import is now effective.
- **Budget:** the `ui-components` ceiling and its baseline come down by
the bytes removed (below). The #36100 and #36109 entries no longer call
this card a payback.
- **Tests:** about 30 fields test files import the body by its new path
(`GridFieldWidget as GridField`); the helpers stay on `./GridField`.
Three plugin-form test files await `preloadGridField()` at module scope.
### The bytes (in the budget file's "Raising it" style)
One container, one instrument: `CI=true pnpm exec turbo run build
--filter=@object-ui/console...`, reading
`apps/console/dist/eager-closure.json`, run twice on one tree. The first
build is `main` at `b3bcfefc` alone; the second is the same `main` plus
this change, at `3c422050`. Gzipped bytes:
| chunk | `b3bcfefc` | `3c422050` | delta |
|---|---:|---:|---:|
| `vendor-objectstack` | 674,662 | 674,662 | 0 |
| `i18n-locale-en` | 66,785 | 66,785 | 0 |
| `framework` | 88,559 | 88,559 | 0 |
| `ui-components` | 352,359 | 346,403 | −5,956 |
| ⇒ aggregate | 1,875,902 | 1,869,974 | −5,928 |
- The same 105 eager chunks appear by name in both builds. Total chunks
go from 2,577 to 2,578; the new one is `fields-grid`, which is lazy
(20,374 raw bytes).
- Apart from `ui-components`, no chunk moved by more than 31 bytes
(`index` +31).
- Raw minified `ui-components`: 1,309,110 → 1,289,869 (−19,241).
- Re-read on this PR's final head (`eb102830`, same instrument):
`ui-components` is still 346,403, and the aggregate is 1,869,971 (−3
bytes against `3c422050`, spread over `index`, `src`, `relativeTime` and
`useConsoleActionRuntime`).
- An intermediate read at `4ca78ed1` (before the face became a JSX-free
`.ts`) gave 346,399 (−5,960). The ceiling follows the final tree's
−5,956.
| constant | before | after | delta |
|---|---:|---:|---:|
| `PER_CHUNK_GZIP_CEILINGS['ui-components']` | 451,100 | 445,144 |
−5,956 |
| `PER_CHUNK_BASELINE['ui-components']` | 265,937 | 259,981 | −5,956 |
The gap between ceiling and baseline is unchanged (185,163). ⛔ Not
moved: `MAX_EAGER_CLOSURE_GZIP_BYTES`, `BASELINE`,
`REGRESSION_THIS_GATE_MUST_CATCH_BYTES` and the other per-chunk rows. No
exemption was added. `pnpm check:eager-closure` on the final build: `✅
chunk ui-components 338.3 KB measured / 434.7 KB ceiling`, plus the
membership line `its src/widgets/grid-field subtree 1 in fields-grid,
exactly`.
## Tests
<details><summary>The first-open pin (live e2e,
ui/e2e/live/master-detail.spec.ts)</summary>
The new describe is "the line-item grid on a form's first open
(objectstack#36102)". The spec is in the required `test:e2e:live:ci`
lane.
- An init script installs a `MutationObserver` before the document's
first byte. It counts every attach of the placeholder
(`grid-field-loading`) and of the grid (`line-items`). The grid count is
the observer's control.
- **Create:** the invoices list → New → the dialog's grid is visible →
add a line → type `first-open` into the Description cell. The cell must
still be focused after 300 ms and hold the text. Assertions: grid
attaches > 0, placeholder attaches = 0.
- **Edit:** `INV-1002`'s edit route. Its stored lines are drawn
(Description not empty), then the same typing and the same counts.
Local live stack: the workspace backend
(`ui/e2e/live/ci/start-backend.sh`) and `vite preview` of a root-base
console build, as the CI job runs them.
- **Red first.** At `e581a9a5`, before `MasterDetailForm` gated the
grid, the create case failed: `the grid never mounted on its loading
placeholder: Expected: 0, Received: 1`. A trace showed the placeholder
attached inside `md-collection` about 0.4 s before the grid, because the
collection drew authored-but-untyped columns while the derivation was in
flight.
- **Then green.** At `51af8021`: `--repeat-each 3 --retries 0` → `15
passed (1.1m)` (the whole spec, 5 tests × 3).
</details>
<details><summary>Unit: the lazy face, and its ablation</summary>
`GridField.test.tsx`, new describe "GridField — the lazy face the
package exports (objectstack#36102)", using `vi.resetModules()` and a
fresh import:
- A mount before the body loads shows the placeholder, then the grid. A
focused Description cell is still connected and still
`document.activeElement` after a re-render.
- After `await preloadGridField()`, `LineItemsField` renders with no
placeholder.
- `LineItemsField` is `GridField`, the same face.
**Ablation** (committed first, through `node
scripts/ablation-replace.mjs`): `const [loadedAtMount] =
React.useState(() => gridFieldWidgetModule);` was replaced by `const
loadedAtMount = gridFieldWidgetModule;`, so the decision is re-read on
every render.
- Anchor 1 → 0, blob `2e286b33ebdf → 1f484acf48d9`.
- Result: `× a mount before the body loads shows the placeholder, then
the grid, and a later render keeps the focused cell`, with `Tests 1
failed | 91 passed (92)`.
- Restored: blob == HEAD (`2e286b33ebdf`) and `git diff HEAD` empty.
</details>
<details><summary>Suites</summary>
- `pnpm exec vitest run packages/plugin-form/` (from `ui/`): `Test Files
244 passed (244)`, `Tests 2750 passed | 1 skipped`.
- `pnpm exec vitest run packages/fields/
scripts/__tests__/check-eager-closure-budget.test.ts
scripts/__tests__/vite-ineffective-dynamic-imports.test.ts
scripts/__tests__/vite-declared-lazy-views.test.ts`: `Test Files 323
passed | 1 skipped (324)`, `Tests 5064 passed | 7 skipped`.
- `pnpm --filter @object-ui/plugin-form run type-check` and `pnpm
--filter @object-ui/fields run type-check`: both exit 0, after a rebuilt
fields `dist`.
- `pnpm --dir ui exec vitest run scripts/`: exit 0 (part of the derived
gate list).
</details>
## Acceptance notes
- **Clause-② is `yes (widening)`, not the claim's `no`.** The new
published export `preloadGridField()` widens `@object-ui/fields`'s
surface; every existing export keeps its name and shape. It is needed so
a host can have the grid's body in its first render, as the record forms
do.
- **On a cold first open, a master-detail collection shows "Loading
columns…" until the child schema and the grid's body are both in.** The
body load starts on mount and overlaps the schema fetch. A form that
mounts after the body has settled draws its grid at first paint.
- Before this PR, a collection with authored, untyped columns drew those
columns at once and drew them again when the derivation landed.
- **`LineItemsPanel` (the record page's read panel) starts the load but
does not gate on it.** It draws its grid after its own fetches. The pin
covers the create and edit forms the card names.
- **Overlap:** two same-seat drafts conflict with the move of
`widgets/GridField.tsx` to `widgets/grid-field/GridFieldWidget.tsx`.
- #36351 conflicts in `GridField.lookupAutofill-28245.test.tsx` and the
widget body.
- #36392 conflicts in `GridField.test.tsx` and the widget body.
- Whichever lands second re-applies its body hunks to
`grid-field/GridFieldWidget.tsx`. The landing order is the seat's call.
`origin/main` merges cleanly.
- **Outside the claim's file surface:**
`packages/spec/liveness/field.json`, whose evidence pointer moved to the
helper's new file (`check:liveness` exit 0).
- **Out of scope, for the seat to file (L1-d 7078535343):** `React.lazy`
caches a first load failure for the whole session, so a host that
renders `GridField` without `preloadGridField()` and hits one failed
chunk load never recovers until a reload.
- **Possible further carve-out, not done here:**
`widgets/gridCellPanels.tsx` is imported only by the body and could
follow it into `fields-grid` (about 2.5 KB gzip by estimate, not
measured).
## Verification
Read first, by risk:
1. `ui/packages/fields/src/widgets/GridField.ts`: the face, specifically
`GridField`'s `useState(() => gridFieldWidgetModule)` and
`loadGridFieldWidget`'s retry-on-failure.
2. `ui/packages/plugin-form/src/MasterDetailForm.tsx`:
`useGridBodySettled` and the `!d.columns?.length || !gridBodyReady` arm.
3. `ui/scripts/check-eager-closure-budget.mjs`: the LOWERED entry, the
baseline note and the carve-out row.
Two-minute check: `cd ui && pnpm exec vitest run
packages/fields/src/widgets/GridField.test.tsx`. Expect `Tests 92 passed
(92)`, including the three cases of the "lazy face" describe.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jV3scu6UYPb42n5okQ)_
<!-- signed: repo:objectstack#7 · zhuangjianguo ·
session_01QsR2jV3scu6UYPb42n5okQ -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 50d6da8 commit 0628e08
51 files changed
Lines changed: 858 additions & 421 deletions
File tree
- .changeset
- packages/spec/liveness
- ui
- apps/console
- e2e/live
- packages
- fields/src
- __tests__
- widgets
- grid-field
- plugin-form/src
- __tests__
- scripts
- __tests__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
| 401 | + | |
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1507 | 1507 | | |
1508 | 1508 | | |
1509 | 1509 | | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
1510 | 1534 | | |
1511 | 1535 | | |
1512 | 1536 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
0 commit comments