Repository navigation
fix(fields): lazy field widgets load again after a failed chunk load - #36786
Merged
Merged
Conversation
…ough load(); the form-field census reads it
Contributor
Author
|
repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj 维护者速读日期、富文本、筛选条件、图片裁剪这些按需加载的控件,网络一抖第一次没加载成功,以前要刷新整页才能恢复;现在下一次打开就会重新加载。加载过程中的「加载中」显示不变。 席位核对 — ACCEPT (L1) · repo:objectstack#1 · head
|
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Warren · project thread
Fixes #36608
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
ui/packages/fields/src/recoverableLazy.ts(not exported from the package entry). It isReact.lazywith one difference: a failed chunk load is not kept for the session.React.lazy: the mount suspends to the host's nearestSuspenseboundary, a mount after the chunk loaded renders in the same pass, and every mount shares one request. Hosts that wait onSuspenseto reveal a form body keep doing so.React.lazysite 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, andregisterField(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/srcnow hits only the helper and comments.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.tsxreadReact.lazy's private_init/_payloadoffgetLazyFieldWidget's result to reach each widget's render function; it now callsload(). CI caught this at b572a58 (Test UI (13/16):TypeError: internals._init is not a function); at 672b03e that file passes locally (37 tests).GridFieldkeeps its own loader from fix(fields): a failed first load of the line-item grid body recovers on the next mount #36607 unchanged.@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'sSuspensefallback (the form bodies' pending skeletons, the action dialogs' widget fallbacks) and the host would reveal half-loaded forms. The helper keepsSuspenseon 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:StrictMode.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.resetModulesplus a module mock of that site's chunk, which would leak into the existing shared files' other tests.Acceptance notes
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:
ui/packages/fields/src/recoverableLazy.ts, the whole file (the stand-in's commit-then-throw is the part that matters).ui/packages/fields/src/index.tsx,getLazyFieldWidgetandregisterField.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 pinningload(), 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'sload(), the new test file and the census test, all re-run above, andtype-checkre-ran at 672b03e: exit 0.pnpm --filter @object-ui/fields type-check(both tsc programs; the new test file is intsconfig.test.json's program,--listFilescounts 1): exit 0.scripts/ablation-replace.mjs(anchor hit 1 to 0, restore proven by blob equals HEAD and emptygit diff HEAD); the tests import source, so no rebuild leg:attempt.retired = false): 10 of 12 red (both helper failure pins and all 8 site pins).getLazyFieldWidgetback onReact.lazy: its site pin red.dispatch-gates.mjs --commands), exit codes captured before any pipe: 36 run, all exit 0, includingcheck:type-check-debt,check:test-source-alias(first red on a dynamic@object-ui/coreimport 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 andcheck-adr-0087-registration. Left to CI:check:published-files,check:driver-memory-census,pnpm --dir ui exec vitest run scripts/.scripts/pm/overlap-check.mjsbefore each push: VERDICT clean (origin/main merges cleanly, 0 open PR heads share a file).