Full Pages
No suspense, slow data loading
This example was originally created as one of several examples I wrote for a post about async React Server Components. See that post for a more detailed explanation of the concepts here.
This example shows how to slow-loading data calls can cause an asynchronous server Page component to delay interactivity.
First we create a function called slowDataLoad
, which just simulates a database call that takes 2 seconds to resolve, returning a string. slowDataLoad
is an async function, so while it is running the async function Page
function, which renders the page, will block until the 2 second data load has completed.
Try to avoid async/await in these situations
As you can see, this approach allows us to write async/await code, which is syntactically great, but it also lead to a worst-possible outcome for the user, who had to wait until all the data were fetched before the application would even show one pixel.
If you have data to load from sources that you have high confidence can be retrieved in the order of 10ms, using async
in your Page definitions will not have a serious impact on performance, but anything that can take significantly longer than 10ms to fetch should be wrapped in a Suspense boundary approach so that UI can be shown to the user almost instantly.
Live Demo
This example can't be easily inlined as it demonstrates how a full-page feels to the end user. Here it is inside an iframe, and there's a looping video below too.
Video Preview
In case the iframe doesn't work for some reason, this is a looping video of what you would see. Click the video to open the full page example in a new tab.