Top level fallback for <Suspense> not being displayed
Answered
Savannah posted this in #help-forum
SavannahOP
Hello everyone, so I have this simple app which is using latest Next.js version and it's really just a single
The problem is, when I go to
Should it immediately display
page.tsx:import {Suspense} from 'react';
async function Sleep(props: {level: number}) {
await new Promise(resolve => setTimeout(resolve, 5000));
const nextLevel = props.level - 1;
return (
<>
<p>Sleep level {props.level} loaded</p>
{nextLevel && (
<Suspense fallback={<p>Sleep level {nextLevel} loading</p>}>
<Sleep level={nextLevel} />
</Suspense>
)}
</>
);
}
export default async function Home() {
return (
<Suspense fallback={<p>Loading root</p>}>
<Sleep level={10} />
</Suspense>
);
}The problem is, when I go to
http://localhost:3000 the browser hangs for 5 seconds and displays:Sleep level 10 loaded
Sleep level 9 loadingShould it immediately display
<p>Loading root</p> instead? Thanks!Answered by Savannah
I guess it might be some WSL2 tcp/socket shenanigans... Thanks, everyone!
14 Replies
if you use the app dir, you can use the loading.js file to show the right thing to the right time ðŸ‘
@Savannah
@Savannah
Shy Albatross
what you're doing is not Suspense compatible
basically it won't actually suspend the component, it will just await and render it when it resolves, that's why you see it "hang" for 5s, because that's your delay
read the Note box here
https://react.dev/reference/react/Suspense
https://react.dev/reference/react/Suspense
if you want to actually trigger the Suspense, you have to use something Suspense-enabled, as they call it
I do it here with
cookies: https://github.com/wlechowicz/next14-ppr-vercel/blob/main/app/SuspendedComponent.tsx#L12@Shy Albatross read the Note box here
https://react.dev/reference/react/Suspense
SavannahOP
Sorry but I still don't get it. If Sleep isn't suspense compatible, why does nested children activate suspense's fallback?
I would expect seeing any
I would expect seeing any
Sleep level n loading.. on my screen@Shy Albatross I do it here with `cookies`: https://github.com/wlechowicz/next14-ppr-vercel/blob/main/app/SuspendedComponent.tsx#L12
SavannahOP
I've just tried your example and I get the same result: no suspense fallback
I'm using latest Node.js, Firefox and WSL2 btw
SavannahOP
WTF
it works on my mac
SavannahOP
I guess it might be some WSL2 tcp/socket shenanigans... Thanks, everyone!
Answer
SavannahOP
It was Kaspersky... Disabling the AV fixed the issue.