@@ -881,29 +881,63 @@ describe('app dir - navigation', () => {
881881 } )
882882
883883 describe ( 'navigating to a page with async metadata' , ( ) => {
884- it ( 'should render the final state of the page with correct metadata' , async ( ) => {
884+ it ( 'shows a fallback when prefetch was pending' , async ( ) => {
885+ const resolveMetadataDuration = 5000
885886 const browser = await next . browser ( '/metadata-await-promise' )
886887
887- // dev doesn't trigger the loading boundary as it's not prefetched
888- if ( isNextDev ) {
889- await browser
890- . elementByCss ( "[href='/metadata-await-promise/nested']" )
891- . click ( )
892- } else {
893- const loadingText = await browser
894- . elementByCss ( "[href='/metadata-await-promise/nested']" )
895- . click ( )
896- . waitForElementByCss ( '#loading' )
897- . text ( )
888+ // Hopefully this click happened before the prefetch was completed.
889+ // TODO: Programmatically trigger prefetch e.g. by mounting the link later.
890+ await browser
891+ . elementByCss ( "[href='/metadata-await-promise/nested']" )
892+ . click ( )
898893
899- expect ( loadingText ) . toBe ( 'Loading' )
894+ if ( ! isNextDev ) {
895+ // next-dev has no prefetch
896+ expect (
897+ await browser
898+ . waitForElementByCss (
899+ '#loading' ,
900+ // Wait a bit longer than the prefetch duration since the click takes a while to register and the fallback render also takes time.
901+ resolveMetadataDuration + 500
902+ )
903+ . text ( )
904+ ) . toEqual ( 'Loading' )
905+ expect ( await browser . elementByCss ( 'title' ) . text ( ) ) . toBe ( 'Async Title' )
900906 }
901907
902- await retry ( async ( ) => {
903- expect ( await browser . elementById ( 'page-content' ) . text ( ) ) . toBe ( 'Content' )
908+ await waitFor ( resolveMetadataDuration )
909+
910+ expect ( await browser . elementById ( 'page-content' ) . text ( ) ) . toBe ( 'Content' )
911+ } )
912+
913+ it ( 'shows a fallback when prefetch completed' , async ( ) => {
914+ const resolveMetadataDuration = 5000
915+ const browser = await next . browser ( '/metadata-await-promise' )
916+
917+ if ( ! isNextDev ) {
918+ await waitFor ( resolveMetadataDuration + 500 )
919+ }
904920
921+ await browser
922+ . elementByCss ( "[href='/metadata-await-promise/nested']" )
923+ . click ( )
924+
925+ if ( ! isNextDev ) {
926+ expect (
927+ await browser
928+ . waitForElementByCss (
929+ '#loading' ,
930+ // Give it some time to commit
931+ 100
932+ )
933+ . text ( )
934+ ) . toEqual ( 'Loading' )
905935 expect ( await browser . elementByCss ( 'title' ) . text ( ) ) . toBe ( 'Async Title' )
906- } )
936+
937+ await waitFor ( resolveMetadataDuration + 500 )
938+ }
939+
940+ expect ( await browser . elementById ( 'page-content' ) . text ( ) ) . toBe ( 'Content' )
907941 } )
908942 } )
909943
0 commit comments