@@ -1576,10 +1576,10 @@ describe('GridField — the lazy face the package exports (objectstack#36102)',
15761576 expect ( cell . value ) . toBe ( 'Widget' ) ;
15771577 } ) ;
15781578
1579- // objectstack#36451 — a host that renders the face without preloading, whose
1580- // first request for the body fails once (a network blip, a deploy that
1579+ // objectstack#36451 — a host that renders the grid without preloading it,
1580+ // whose first request for the body fails once (a network blip, a deploy that
15811581 // swapped chunk names), must not keep that failure for the whole session.
1582- it ( 'a mount after a failed load of the body renders the grid once the body is reachable, with no reload' , async ( ) => {
1582+ describe ( ' after one failed load of the body' , ( ) => {
15831583 class Boundary extends React . Component < { children : React . ReactNode } , { failed : boolean } > {
15841584 state = { failed : false } ;
15851585 static getDerivedStateFromError ( ) {
@@ -1589,29 +1589,54 @@ describe('GridField — the lazy face the package exports (objectstack#36102)',
15891589 return this . state . failed ? < div data-testid = "grid-load-failed" /> : this . props . children ;
15901590 }
15911591 }
1592- vi . resetModules ( ) ;
1593- let failNextLoad = true ;
1594- vi . doMock ( './grid-field/GridFieldWidget' , async ( importOriginal ) => {
1595- if ( failNextLoad ) {
1596- failNextLoad = false ;
1597- throw new Error ( 'Failed to fetch dynamically imported module: fields-grid' ) ;
1598- }
1599- return importOriginal ( ) ;
1600- } ) ;
1601- const quiet = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
1602- try {
1603- const face = await import ( './GridField' ) ;
1604- const first = render ( < Boundary > < face . GridField value = { lines } onChange = { ( ) => { } } field = { field } /> </ Boundary > ) ;
1592+
1593+ /** Fail the next load of the body once, then let it through; restored by the returned call. */
1594+ function failTheNextBodyLoad ( ) : ( ) => void {
1595+ vi . resetModules ( ) ;
1596+ let failNextLoad = true ;
1597+ vi . doMock ( './grid-field/GridFieldWidget' , async ( importOriginal ) => {
1598+ if ( failNextLoad ) {
1599+ failNextLoad = false ;
1600+ throw new Error ( 'Failed to fetch dynamically imported module: fields-grid' ) ;
1601+ }
1602+ return importOriginal ( ) ;
1603+ } ) ;
1604+ const quiet = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
1605+ return ( ) => {
1606+ quiet . mockRestore ( ) ;
1607+ vi . doUnmock ( './grid-field/GridFieldWidget' ) ;
1608+ } ;
1609+ }
1610+
1611+ async function expectFailedThenRecovered ( Grid : React . ComponentType < React . ComponentProps < typeof GridFieldFace > > ) : Promise < void > {
1612+ const first = render ( < Boundary > < React . Suspense fallback = { null } > < Grid value = { lines } onChange = { ( ) => { } } field = { field } /> </ React . Suspense > </ Boundary > ) ;
16051613 await screen . findByTestId ( 'grid-load-failed' ) ;
16061614 first . unmount ( ) ;
16071615
1608- render ( < Boundary > < face . GridField value = { lines } onChange = { ( ) => { } } field = { field } /> </ Boundary > ) ;
1616+ render ( < Boundary > < React . Suspense fallback = { null } > < Grid value = { lines } onChange = { ( ) => { } } field = { field } /> </ React . Suspense > </ Boundary > ) ;
16091617 const cell = ( await screen . findByTestId ( 'line-items' ) ) . querySelector ( 'input[aria-label="Description"]' ) as HTMLInputElement ;
16101618 expect ( cell . value ) . toBe ( 'Widget' ) ;
16111619 expect ( screen . queryByTestId ( 'grid-load-failed' ) ) . toBeNull ( ) ;
1612- } finally {
1613- quiet . mockRestore ( ) ;
1614- vi . doUnmock ( './grid-field/GridFieldWidget' ) ;
16151620 }
1621+
1622+ it ( 'a later mount of GridField renders the grid once the body is reachable, with no reload' , async ( ) => {
1623+ const restore = failTheNextBodyLoad ( ) ;
1624+ try {
1625+ const face = await import ( './GridField' ) ;
1626+ await expectFailedThenRecovered ( face . GridField ) ;
1627+ } finally {
1628+ restore ( ) ;
1629+ }
1630+ } ) ;
1631+
1632+ it ( 'a later mount of the grid form-field widget renders the grid too' , async ( ) => {
1633+ const restore = failTheNextBodyLoad ( ) ;
1634+ try {
1635+ const fields = await import ( '../index' ) ;
1636+ await expectFailedThenRecovered ( fields . getLazyFieldWidget ( 'grid' ) ) ;
1637+ } finally {
1638+ restore ( ) ;
1639+ }
1640+ } ) ;
16161641 } ) ;
16171642} ) ;
0 commit comments