Skip to content

fix(fields): lazy field widgets load again after a failed chunk load - #36786

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-b3g1v2
Nov 23, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-b3g1v2

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Fixes #36608

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:表单和列表里的日期、日期时间、富文本、筛选条件、图片裁剪等控件,某次加载失败(刚发版换了文件、网络断了一下)后,重新打开表单或页面即可恢复,不用再整页刷新。
  • 为什么做:同类问题之前只修了明细行表格这一处,这次把字段包里其余所有延迟加载的控件一次收口到同一个机制上。
  • 出错会怎样:最坏是某个控件在首次加载时多等一下或仍显示加载失败,可直接撤回本次改动,不涉及数据。
  • 要你做什么:无。

What changes

  • New internal helper ui/packages/fields/src/recoverableLazy.ts (not exported from the package entry). It is React.lazy with one difference: a failed chunk load is not kept for the session.
    • Loading and loaded behave as React.lazy: the mount suspends to the host's nearest Suspense boundary, a mount after the chunk loaded renders in the same pass, and every mount shares one request. Hosts that wait on Suspense to reveal a form body keep doing so.
    • A failed load resolves to a stand-in that commits once (draws nothing), retires that request, then throws the failure from its next render to the nearest error boundary. The committed mount keeps rethrowing for as long as it is re-rendered; only a NEW mount (an error boundary's reset, a reopened form, a revisited page) asks for the chunk again.
  • Every React.lazy site in the fields package now goes through it: FieldEditWidget (date, datetime, the rich text cell-panel editor), richTextDisplay (markdown read face), FilterConditionCell, ImageField's crop dialog, getLazyFieldWidget, and registerField (the form registry path; the card's re-check grep lists it, so it is in scope). git grep -n "React.lazy\|lazy(" ui/packages/fields/src now hits only the helper and comments.
  • The returned component also carries load(), which resolves to the loaded widget itself through the same shared request (and asks again after a failure). getLazyFieldWidget's declared return type is unchanged (React.ComponentType); load() is the seam for a caller that needs the widget's own function rather than an element of it.
  • ui/examples/schema-catalog/test/form-field-channel-census-12130.test.tsx read React.lazy's private _init/_payload off getLazyFieldWidget's result to reach each widget's render function; it now calls load(). CI caught this at b572a58 (Test UI (13/16): TypeError: internals._init is not a function); at 672b03e that file passes locally (37 tests).
  • GridField keeps its own loader from fix(fields): a failed first load of the line-item grid body recovers on the next mount #36607 unchanged.
  • Patch changeset for @object-ui/fields.

Why not #36607's effect-based wrapper as is

The card suggests #36607's approach. That wrapper loads from an effect and draws its own loading face, so it never suspends. Applied to getLazyFieldWidget / registerField, every cold-loaded form field would stop suspending to its host's Suspense fallback (the form bodies' pending skeletons, the action dialogs' widget fallbacks) and the host would reveal half-loaded forms. The helper keeps Suspense on the happy path and borrows #36607's key idea only on the failure path: a request is forgotten only from a committed mount, so the failure is shown instead of retried in a loop.

The tempting simpler variant (forget the failed request in the render that throws) is wrong, and the second ablation below shows it: a mount that never committed keeps no state, so React's re-render after the rejection picks a fresh request, suspends again, and the error never reaches the boundary.

Tests

ui/packages/fields/src/__tests__/lazyWidgetRecovery-36608.test.tsx, 12 tests:

  • the helper: suspends to the host fallback, later mounts render in the same pass, concurrent mounts share one request, a failure reaches the boundary with exactly one request (no retry loop), the next mount loads; the same under StrictMode.
  • one pin per site (date, datetime, rich text panel editor, markdown read face, filter-condition cell, image crop dialog, getLazyFieldWidget('date'), registerField('date')): the chunk module is mocked to fail its first import, the first mount lands on the error boundary, a later mount renders the widget.

One family file rather than a pin per component file: every site pin needs vi.resetModules plus a module mock of that site's chunk, which would leak into the existing shared files' other tests.

Acceptance notes

  • None filed. Nothing out of scope was found.

Verification

Two-minute check: cd ui && pnpm exec vitest run packages/fields/src/__tests__/lazyWidgetRecovery-36608.test.tsx, expect 12 passed.

Read first, by risk:

  1. ui/packages/fields/src/recoverableLazy.ts, the whole file (the stand-in's commit-then-throw is the part that matters).
  2. ui/packages/fields/src/index.tsx, getLazyFieldWidget and registerField.
  3. ui/packages/fields/src/FieldEditWidget.tsx, the three lazy editors.
Local readings at head 672b03e
  • cd ui && pnpm exec vitest run packages/fields/src/__tests__/lazyWidgetRecovery-36608.test.tsx examples/schema-catalog/test/form-field-channel-census-12130.test.tsx: Test Files 2 passed, Tests 49 passed (12 new pins, one of them also pinning load(), plus the census).
  • pnpm --filter @object-ui/fields test: Test Files 326 passed, 1 skipped (327); Tests 4980 passed, 7 skipped (4987). Run at c42f157 plus the typing fix; the later commits touch the helper's load(), the new test file and the census test, all re-run above, and type-check re-ran at 672b03e: exit 0.
  • pnpm --filter @object-ui/fields type-check (both tsc programs; the new test file is in tsconfig.test.json's program, --listFiles counts 1): exit 0.
  • Ablations, each through scripts/ablation-replace.mjs (anchor hit 1 to 0, restore proven by blob equals HEAD and empty git diff HEAD); the tests import source, so no rebuild leg:
    1. the stand-in never retires its request (attempt.retired = false): 10 of 12 red (both helper failure pins and all 8 site pins).
    2. the naive variant (retire and throw in the same render, no commit first): both helper failure pins red; the first mount shows the widget, not the error boundary, because the failure was swallowed and retried behind the loading face.
    3. getLazyFieldWidget back on React.lazy: its site pin red.
  • Derived gate families (dispatch-gates.mjs --commands), exit codes captured before any pipe: 36 run, all exit 0, including check:type-check-debt, check:test-source-alias (first red on a dynamic @object-ui/core import inside a test body, fixed by a module-top import), check:query-options-erasure, check:type-check-coverage, check:nul-bytes, check:cross-package-test-inputs, check:engine-double-contract, the changeset gates and check-adr-0087-registration. Left to CI: check:published-files, check:driver-memory-census, pnpm --dir ui exec vitest run scripts/.
  • scripts/pm/overlap-check.mjs before each push: VERDICT clean (origin/main merges cleanly, 0 open PR heads share a file).

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 23, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj

维护者速读

日期、富文本、筛选条件、图片裁剪这些按需加载的控件,网络一抖第一次没加载成功,以前要刷新整页才能恢复;现在下一次打开就会重新加载。加载过程中的「加载中」显示不变。
要你做的:无(普通改动,席位自动合并)。

席位核对 — ACCEPT (L1) · repo:objectstack#1 · head 672b03e0 · 2026-11-23T23:12Z

  • Shape: Fixes #36608. A new internal ui/packages/fields/src/recoverableLazy.ts (not exported from the package entry) now backs all 8 lazy sites in FieldEditWidget.tsx, index.tsx (getLazyFieldWidget and registerField), widgets/FilterConditionCell.tsx, widgets/ImageField.tsx and widgets/richTextDisplay.tsx. Also a new test file, the schema-catalog census test reading the helper's load() in place of React.lazy's private fields, and a patch changeset. Clause-②: no. Metadata-protocol: none. This is the real file surface; the claim's line is amended by this record.
  • Read: one import in flight is shared and forgotten on failure, so the next asker imports again. A failed attempt renders a stand-in that marks the attempt retired after commit and then rethrows to the host's error boundary. The mount that saw the failure keeps its attempt (no retry loop), and the next mount starts a new one. Host Suspense fallbacks stay on the happy path. The declared return type of getLazyFieldWidget is unchanged. Ref props pass through as plain props under React 19.
  • Acceptance notes: the card's suggested route (fix(fields): a failed first load of the line-item grid body recovers on the next mount #36607's effect-based wrapper) is not taken, because it would drop every host's Suspense fallback on a cold load; the PR body argues this. GridField keeps its own loader.
  • Tests: 12 new pins; the fields package passes 4980 per the thread; 3 reverse runs red as expected.
  • Gates: 46 success, 15 expected skip, 0 failed on 672b03e0; mergeable_state clean.
  • Landing: the seat readies the PR and arms auto-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants