From cfb5f2d69c2bf929b8a1091c279c0ffca62311b5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 01:44:26 +0000 Subject: [PATCH 1/4] test(fields): pin a later GridField mount after a failed body load Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD Co-authored-by: Claude --- .../fields/src/widgets/GridField.test.tsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ui/packages/fields/src/widgets/GridField.test.tsx b/ui/packages/fields/src/widgets/GridField.test.tsx index 3a101598d76..33a8d82b6a8 100644 --- a/ui/packages/fields/src/widgets/GridField.test.tsx +++ b/ui/packages/fields/src/widgets/GridField.test.tsx @@ -1575,4 +1575,43 @@ describe('GridField — the lazy face the package exports (objectstack#36102)', const cell = screen.getByTestId('line-items').querySelector('input[aria-label="Description"]') as HTMLInputElement; expect(cell.value).toBe('Widget'); }); + + // objectstack#36451 — a host that renders the face without preloading, whose + // first request for the body fails once (a network blip, a deploy that + // swapped chunk names), must not keep that failure for the whole session. + it('a mount after a failed load of the body renders the grid once the body is reachable, with no reload', async () => { + class Boundary extends React.Component<{ children: React.ReactNode }, { failed: boolean }> { + state = { failed: false }; + static getDerivedStateFromError() { + return { failed: true }; + } + render() { + return this.state.failed ?
: this.props.children; + } + } + vi.resetModules(); + let failNextLoad = true; + vi.doMock('./grid-field/GridFieldWidget', async (importOriginal) => { + if (failNextLoad) { + failNextLoad = false; + throw new Error('Failed to fetch dynamically imported module: fields-grid'); + } + return importOriginal(); + }); + const quiet = vi.spyOn(console, 'error').mockImplementation(() => {}); + try { + const face = await import('./GridField'); + const first = render( {}} field={field} />); + await screen.findByTestId('grid-load-failed'); + first.unmount(); + + render( {}} field={field} />); + const cell = (await screen.findByTestId('line-items')).querySelector('input[aria-label="Description"]') as HTMLInputElement; + expect(cell.value).toBe('Widget'); + expect(screen.queryByTestId('grid-load-failed')).toBeNull(); + } finally { + quiet.mockRestore(); + vi.doUnmock('./grid-field/GridFieldWidget'); + } + }); }); From a7260b71562e2597438af4e7a9ce69d3e04e46d6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 01:46:44 +0000 Subject: [PATCH 2/4] fix(fields): a failed load of the grid body no longer sticks until a reload The lazy face replaces a React.lazy whose load failed, so the next mount asks the loader again; the grid form-field loader now resolves to that face. Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD Co-authored-by: Claude --- ui/packages/fields/src/index.tsx | 10 +-- .../fields/src/widgets/GridField.test.tsx | 65 +++++++++++++------ ui/packages/fields/src/widgets/GridField.ts | 41 +++++++++--- 3 files changed, 82 insertions(+), 34 deletions(-) diff --git a/ui/packages/fields/src/index.tsx b/ui/packages/fields/src/index.tsx index 46b299d2317..409e038efaf 100644 --- a/ui/packages/fields/src/index.tsx +++ b/ui/packages/fields/src/index.tsx @@ -36,7 +36,7 @@ import { deriveHexBadgePalette } from './hexBadgePalette.js'; import { formatNumberFieldValue, formatCurrency, formatPercentPoints, percentCellScale } from './widgets/number-format.js'; import { useFieldTranslation } from './widgets/useFieldTranslation.js'; import { useBooleanValueLabel } from './widgets/booleanValueLabel.js'; -import { loadGridFieldWidget } from './widgets/GridField.js'; +import { GridField } from './widgets/GridField.js'; import { RecordHoverCard, type RecordHoverCardObjectDef } from './RecordHoverCard.js'; // Module-level cache so multiple renderers fetching the same lookup ID @@ -4832,9 +4832,11 @@ const fieldWidgetMap = { // Complex data types 'object': () => import('./widgets/ObjectField.js').then(m => ({ default: m.ObjectField })), 'vector': () => import('./widgets/VectorField.js').then(m => ({ default: m.VectorField })), - // The grid's body, through its public face's one loader so a lazy `GridField` - // mounted after this resolved renders without a boundary (objectstack#36102). - 'grid': () => loadGridFieldWidget().then(m => ({ default: m.GridFieldWidget })), + // The grid's public face, already in this chunk, not its body: the face loads + // the body through its one loader (objectstack#36102) and asks again after a + // failed load, where a `React.lazy` wrapped around the body here would keep + // the failure until the page is reloaded (objectstack#36451). + 'grid': () => Promise.resolve({ default: GridField }), // Additional field types from @objectstack/spec 'color': () => import('./widgets/ColorField.js').then(m => ({ default: m.ColorField })), diff --git a/ui/packages/fields/src/widgets/GridField.test.tsx b/ui/packages/fields/src/widgets/GridField.test.tsx index 33a8d82b6a8..e136d201b74 100644 --- a/ui/packages/fields/src/widgets/GridField.test.tsx +++ b/ui/packages/fields/src/widgets/GridField.test.tsx @@ -1576,10 +1576,10 @@ describe('GridField — the lazy face the package exports (objectstack#36102)', expect(cell.value).toBe('Widget'); }); - // objectstack#36451 — a host that renders the face without preloading, whose - // first request for the body fails once (a network blip, a deploy that + // objectstack#36451 — a host that renders the grid without preloading it, + // whose first request for the body fails once (a network blip, a deploy that // swapped chunk names), must not keep that failure for the whole session. - it('a mount after a failed load of the body renders the grid once the body is reachable, with no reload', async () => { + describe('after one failed load of the body', () => { class Boundary extends React.Component<{ children: React.ReactNode }, { failed: boolean }> { state = { failed: false }; static getDerivedStateFromError() { @@ -1589,29 +1589,54 @@ describe('GridField — the lazy face the package exports (objectstack#36102)', return this.state.failed ?
: this.props.children; } } - vi.resetModules(); - let failNextLoad = true; - vi.doMock('./grid-field/GridFieldWidget', async (importOriginal) => { - if (failNextLoad) { - failNextLoad = false; - throw new Error('Failed to fetch dynamically imported module: fields-grid'); - } - return importOriginal(); - }); - const quiet = vi.spyOn(console, 'error').mockImplementation(() => {}); - try { - const face = await import('./GridField'); - const first = render( {}} field={field} />); + + /** Fail the next load of the body once, then let it through; restored by the returned call. */ + function failTheNextBodyLoad(): () => void { + vi.resetModules(); + let failNextLoad = true; + vi.doMock('./grid-field/GridFieldWidget', async (importOriginal) => { + if (failNextLoad) { + failNextLoad = false; + throw new Error('Failed to fetch dynamically imported module: fields-grid'); + } + return importOriginal(); + }); + const quiet = vi.spyOn(console, 'error').mockImplementation(() => {}); + return () => { + quiet.mockRestore(); + vi.doUnmock('./grid-field/GridFieldWidget'); + }; + } + + async function expectFailedThenRecovered(Grid: React.ComponentType>): Promise { + const first = render( {}} field={field} />); await screen.findByTestId('grid-load-failed'); first.unmount(); - render( {}} field={field} />); + render( {}} field={field} />); const cell = (await screen.findByTestId('line-items')).querySelector('input[aria-label="Description"]') as HTMLInputElement; expect(cell.value).toBe('Widget'); expect(screen.queryByTestId('grid-load-failed')).toBeNull(); - } finally { - quiet.mockRestore(); - vi.doUnmock('./grid-field/GridFieldWidget'); } + + it('a later mount of GridField renders the grid once the body is reachable, with no reload', async () => { + const restore = failTheNextBodyLoad(); + try { + const face = await import('./GridField'); + await expectFailedThenRecovered(face.GridField); + } finally { + restore(); + } + }); + + it('a later mount of the grid form-field widget renders the grid too', async () => { + const restore = failTheNextBodyLoad(); + try { + const fields = await import('../index'); + await expectFailedThenRecovered(fields.getLazyFieldWidget('grid')); + } finally { + restore(); + } + }); }); }); diff --git a/ui/packages/fields/src/widgets/GridField.ts b/ui/packages/fields/src/widgets/GridField.ts index ee12433323e..4faa0ed87ea 100644 --- a/ui/packages/fields/src/widgets/GridField.ts +++ b/ui/packages/fields/src/widgets/GridField.ts @@ -422,11 +422,12 @@ let gridFieldWidgetModule: GridFieldWidgetModule | undefined; let gridFieldWidgetLoad: Promise | undefined; /** - * The ONE loader of the grid's body: the lazy face below, {@link - * preloadGridField} and the `grid` form-field loader in `../index.tsx` all go - * through it, so the body is requested once and a mount after any of them has - * resolved renders without a boundary. A failed load is forgotten, so the next - * caller asks again rather than inheriting the failure. + * The ONE loader of the grid's body: the lazy face below and {@link + * preloadGridField} go through it (and the `grid` form-field loader in + * `../index.tsx` reaches it through the face), so the body is requested once + * and a mount after any of them has resolved renders without a boundary. A + * failed load is forgotten, so the next caller asks again rather than + * inheriting the failure. */ export function loadGridFieldWidget(): Promise { gridFieldWidgetLoad ??= import('./grid-field/GridFieldWidget.js').then( @@ -458,9 +459,27 @@ export function preloadGridField(): Promise { ); } -const LazyGridFieldWidget = React.lazy(() => - loadGridFieldWidget().then((loaded) => ({ default: loaded.GridFieldWidget })), -); +/** + * The lazy body a mount that finds it still loading renders. `React.lazy` + * keeps its first outcome for good, a rejection included, so a lazy whose load + * failed is replaced by a fresh one: the failed mount still hands the error to + * the nearest error boundary, and the next mount asks the loader again instead + * of rethrowing that failure until the page is reloaded. + */ +let LazyGridFieldWidget = lazyGridFieldWidget(); + +function lazyGridFieldWidget(): React.LazyExoticComponent> { + const lazy = React.lazy(() => + loadGridFieldWidget().then( + (loaded) => ({ default: loaded.GridFieldWidget }), + (error: unknown) => { + if (LazyGridFieldWidget === lazy) LazyGridFieldWidget = lazyGridFieldWidget(); + throw error; + }, + ), + ); + return lazy; +} /** * What a grid mounted before its body arrived shows meanwhile: a box of the @@ -481,8 +500,10 @@ function GridFieldLoading(): React.ReactElement { */ export function GridField(props: GridFieldWidgetProps): React.ReactElement { // Decided once per mount: switching from the boundary to the direct render - // when the load finishes would remount the body and drop the focused cell. + // when the load finishes would remount the body and drop the focused cell, + // and so would switching to the lazy that replaces a failed one. const [loadedAtMount] = React.useState(() => gridFieldWidgetModule); + const [LazyAtMount] = React.useState(() => LazyGridFieldWidget); if (loadedAtMount) { const { GridFieldWidget } = loadedAtMount; return React.createElement(GridFieldWidget, props); @@ -490,7 +511,7 @@ export function GridField(props: GridFieldWidgetProps): React.ReactElement { return React.createElement( React.Suspense, { fallback: React.createElement(GridFieldLoading) }, - React.createElement(LazyGridFieldWidget, props), + React.createElement(LazyAtMount, props), ); } From 86285df8160e1138b8a68208d2097798ea1b353e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 01:47:49 +0000 Subject: [PATCH 3/4] chore(changeset): fields grid lazy retry Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD Co-authored-by: Claude --- .changeset/36451-grid-field-lazy-retry.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .changeset/36451-grid-field-lazy-retry.md diff --git a/.changeset/36451-grid-field-lazy-retry.md b/.changeset/36451-grid-field-lazy-retry.md new file mode 100644 index 00000000000..13773bad197 --- /dev/null +++ b/.changeset/36451-grid-field-lazy-retry.md @@ -0,0 +1,12 @@ +--- +'@object-ui/fields': patch +--- + +fix(fields): a line-item grid whose first load failed loads again on its next mount, with no page reload + +Clause-②: no +Metadata-protocol: none + +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` now replace the lazy body whose load failed, so the failed mount still reports the error to the nearest error boundary and the next mount asks for the body 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. + +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. From 66d9f58b10c86a1113abcee546b92b16f6e866a3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 02:01:48 +0000 Subject: [PATCH 4/4] fix(fields): load the grid body from a committed mount's effect, not React.lazy A render React discards before it commits requests nothing, so a failed load cannot retry in a loop; each later mount asks the loader again. Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD Co-authored-by: Claude --- .changeset/36451-grid-field-lazy-retry.md | 2 +- ui/packages/fields/src/widgets/GridField.ts | 72 ++++++++++++--------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/.changeset/36451-grid-field-lazy-retry.md b/.changeset/36451-grid-field-lazy-retry.md index 13773bad197..88eb6184e65 100644 --- a/.changeset/36451-grid-field-lazy-retry.md +++ b/.changeset/36451-grid-field-lazy-retry.md @@ -7,6 +7,6 @@ fix(fields): a line-item grid whose first load failed loads again on its next mo Clause-②: no Metadata-protocol: none -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` now replace the lazy body whose load failed, so the failed mount still reports the error to the nearest error boundary and the next mount asks for the body 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. +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. 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. diff --git a/ui/packages/fields/src/widgets/GridField.ts b/ui/packages/fields/src/widgets/GridField.ts index 4faa0ed87ea..518e460231e 100644 --- a/ui/packages/fields/src/widgets/GridField.ts +++ b/ui/packages/fields/src/widgets/GridField.ts @@ -422,7 +422,7 @@ let gridFieldWidgetModule: GridFieldWidgetModule | undefined; let gridFieldWidgetLoad: Promise | undefined; /** - * The ONE loader of the grid's body: the lazy face below and {@link + * The ONE loader of the grid's body: the face below and {@link * preloadGridField} go through it (and the `grid` form-field loader in * `../index.tsx` reaches it through the face), so the body is requested once * and a mount after any of them has resolved renders without a boundary. A @@ -459,28 +459,6 @@ export function preloadGridField(): Promise { ); } -/** - * The lazy body a mount that finds it still loading renders. `React.lazy` - * keeps its first outcome for good, a rejection included, so a lazy whose load - * failed is replaced by a fresh one: the failed mount still hands the error to - * the nearest error boundary, and the next mount asks the loader again instead - * of rethrowing that failure until the page is reloaded. - */ -let LazyGridFieldWidget = lazyGridFieldWidget(); - -function lazyGridFieldWidget(): React.LazyExoticComponent> { - const lazy = React.lazy(() => - loadGridFieldWidget().then( - (loaded) => ({ default: loaded.GridFieldWidget }), - (error: unknown) => { - if (LazyGridFieldWidget === lazy) LazyGridFieldWidget = lazyGridFieldWidget(); - throw error; - }, - ), - ); - return lazy; -} - /** * What a grid mounted before its body arrived shows meanwhile: a box of the * grid's header height, marked busy, so the form does not jump when the table @@ -499,20 +477,50 @@ function GridFieldLoading(): React.ReactElement { * props as the body, see `GridFieldWidgetProps`. */ export function GridField(props: GridFieldWidgetProps): React.ReactElement { - // Decided once per mount: switching from the boundary to the direct render - // when the load finishes would remount the body and drop the focused cell, - // and so would switching to the lazy that replaces a failed one. + // Decided once per mount: switching from the loading face to the direct + // render when the load finishes would remount the body and drop the focused + // cell. const [loadedAtMount] = React.useState(() => gridFieldWidgetModule); - const [LazyAtMount] = React.useState(() => LazyGridFieldWidget); if (loadedAtMount) { const { GridFieldWidget } = loadedAtMount; return React.createElement(GridFieldWidget, props); } - return React.createElement( - React.Suspense, - { fallback: React.createElement(GridFieldLoading) }, - React.createElement(LazyAtMount, props), - ); + return React.createElement(GridFieldOnceLoaded, props); +} + +type GridFieldLoadOutcome = + | { readonly loaded: GridFieldWidgetModule } + | { readonly failed: unknown }; + +/** + * A grid mounted before its body arrived: {@link GridFieldLoading} until the + * body loads, then the body. Each COMMITTED mount asks the loader once, from an + * effect, and a failed load is thrown from the next render to the nearest + * error boundary. Not `React.lazy`: a lazy component keeps its first outcome + * for good, a rejection included, so a later mount would rethrow that failure + * until the page is reloaded. A render React discards before it commits runs + * no effect, so it requests nothing, and the loader forgets a failure, so the + * next mount (an error boundary's reset, a reopened form) loads again. + */ +function GridFieldOnceLoaded(props: GridFieldWidgetProps): React.ReactElement { + const [outcome, setOutcome] = React.useState(undefined); + React.useEffect(() => { + let mounted = true; + loadGridFieldWidget().then( + (loaded) => { + if (mounted) setOutcome({ loaded }); + }, + (failed: unknown) => { + if (mounted) setOutcome({ failed }); + }, + ); + return () => { + mounted = false; + }; + }, []); + if (!outcome) return React.createElement(GridFieldLoading); + if ('failed' in outcome) throw outcome.failed; + return React.createElement(outcome.loaded.GridFieldWidget, props); } /** Semantic alias — the master-detail subform's child grid. */