You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 52971ff
Browse filesBrowse the repository at this point in the historyBrowse files
fix(fields): a failed first load of the line-item grid body recovers on the next mount (#36607)
Fixes#36451
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:控制台记录表单里的明细行表格,第一次加载失败一次后(网络抖动、发版换了文件名),之后再打开表单即可正常显示表格,不用刷新整页。
- 为什么做:明细行表格按需加载的收尾问题,替所有碰到一次加载失败的表单用户解决「只能刷新页面」。
- 出错会怎样:只影响明细行表格的加载方式,最坏是加载失败时照旧显示报错;可直接撤回。
- 要你做什么:无。
## What changes
- `GridField` / `LineItemsField`
(`ui/packages/fields/src/widgets/GridField.ts`) no longer render the
body through a module-scope `React.lazy`. A lazy component keeps its
first outcome for good, a rejection included, so after one failed load
of the body every later mount rethrew that failure until the page was
reloaded, although `loadGridFieldWidget` already forgot the failure. A
mount that finds the body still loading now renders
`GridFieldOnceLoaded`: it shows the existing loading placeholder, asks
the one loader from an effect (so only a committed mount requests
anything; a render React discards before commit cannot loop on a failing
chunk), throws a failed load to the nearest error boundary, and the next
mount asks again. A mount after the body has loaded still renders it
directly in the same render; `preloadGridField()` is unchanged and never
rejects.
- The `grid` entry of the form-field loader map
(`ui/packages/fields/src/index.tsx`) resolves to that face instead of a
`React.lazy` around the body, so the registered `field:grid` widget and
`getLazyFieldWidget('grid')` recover the same way. The face is already
in the eager chunk (the entry exports it), so this adds no edge to the
body.
- Patch changeset for `@object-ui/fields`.
Read first, by risk:
1. `GridField.ts`, the `GridFieldOnceLoaded` function: the effect-driven
load, the cleanup guard, the throw of a failed outcome.
2. `index.tsx`, the `grid` entry of the loader map.
3. `GridField.test.tsx`, the new `after one failed load of the body`
describe inside the existing lazy-face block.
## Tests
Two pins in the existing lazy-face block of `GridField.test.tsx`: the
body module is mocked to fail its first load once and then load
normally; the first mount must reach the error boundary and a later
mount must render the grid, once for the `GridField` face and once for
`getLazyFieldWidget('grid')`.
<details><summary>Premise, measured on main's code (both pins
red)</summary>
`GridField.ts` and `index.tsx` replaced by their blobs at the branch
point `e17c2ae1a` (hash-verified on disk), then the pins run:
```
× a later mount of GridField renders the grid once the body is reachable, with no reload
× a later mount of the grid form-field widget renders the grid too
Tests 2 failed | 107 skipped (109)
```
Both failures: the later mount shows the boundary fallback
(`grid-load-failed`), never `line-items`. Restored with `git checkout
HEAD`, `git diff HEAD` empty, HEAD blob hashes matched.
</details>
<details><summary>Ablation, one half at a time</summary>
- Face reverted to main, `index.tsx` fixed: both pins red (the
form-field entry reaches the reverted face).
- `index.tsx` reverted to main, face fixed: only the form-field pin red
(`1 failed | 1 passed`).
Each leg restored and verified the same way.
</details>
<details><summary>Package run at head 66d9f58</summary>
`pnpm --dir ui exec vitest run --maxWorkers=2 packages/fields/ && pnpm
--filter @object-ui/fields run type-check` under the shared verify lock:
```
Test Files 322 passed | 1 skipped (323)
Tests 4893 passed | 7 skipped (4900)
VERDICT command-exit 0
```
`pnpm --dir ui exec vitest run scripts/` (derived gate): 172 files
passed, VERDICT command-exit 0. ESLint on the three changed files: 0
errors (warnings pre-existing).
</details>
<details><summary>Derived gates at head 66d9f58</summary>
`dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`
derived 39 families; all 39 run, all exit 0, `--ran` reconciliation: 39
run, 0 NOT-MEASURED, 0 UNRUN. First pass: `check:query-options-erasure`
and `check:type-check-debt` hit a 300 s harness timeout and
`check:watch-hint-literal` exited 1 once (cause not established); each
re-run to completion, exit 0.
</details>
## Acceptance notes
- A form drawing a `grid` field now shows the grid's own loading
placeholder (a dashed box of the header's height) while the body loads,
where it showed the form's own suspense fallback before.
- Boundary not measured here: the retry calls `import()` again for the
same chunk URL. Whether a given browser re-fetches a module whose
earlier dynamic import failed is engine behaviour; the pins run under
vitest/jsdom only.
- Card step 3, measured with a throwaway test (deleted, not committed):
the same edge, a module-scope `React.lazy` keeping a failed first load
until reload, holds for `FieldEditWidget`'s date picker (measured; its
datetime picker and rich-text panel are the same construction),
`richTextDisplay`'s markdown content (measured), `FilterConditionCell`
(measured), the per-type lazy cache of `getLazyFieldWidget` and
`registerField` for every other type (measured for `date`), and
`ImageField`'s cropper dialog (same construction, not measured). None is
changed here; they are listed for the seat.
- No README or docs sentence is made false by this change.
## Verification
Two-minute check: `pnpm --dir ui exec vitest run
packages/fields/src/widgets/GridField.test.tsx -t "after one failed
load"` from the repo root; expect `2 passed`.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(fields): a line-item grid whose first load failed loads again on its next mount, with no page reload
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
The line-item grid's body loads on first use. When that first load failed once (a network blip, a deploy that swapped chunk names) and the host had not preloaded it, the grid showed its error from then on, even after the body was reachable again, until the page was reloaded. `GridField` / `LineItemsField` no longer hold the body in a `React.lazy`, which keeps a failed load for good: each mount that finds the body still loading asks for it once, a failure still reaches the nearest error boundary, and the next mount asks again. The `grid` form-field widget (the registered `field:grid` and `getLazyFieldWidget('grid')`) now resolves to that same face, so it recovers the same way.
11
+
12
+
What does not change: a mount after the body has loaded renders it directly, `preloadGridField()` still never rejects, and the props of both names are unchanged. A form drawing a `grid` field shows the grid's own loading placeholder while the body loads. No metadata key, value or default changes.
0 commit comments