Next.js Discord

Discord Forum

Top level await

Answered
Bohemian Shepherd posted this in #help-forum
Open in Discord
Bohemian ShepherdOP
Does top level await work with next.js app router? Works on RSC but throws an error when I try it on a client file. I see some history that it was added in next 13.4.5 but it’s not working for me in next 15 and I have a feeling it was removed because the e2e test is missing
Answered by B33fb0n3
yea it works, but only in server components, not in client components
View full answer

4 Replies

Answer
Roseate Spoonbill
awaited component can only be a server component. You can implement suspense-compatible client-side component, but in such case you need to fetch data in a different way (e.g. with useSuspenseQuery from TanStack Query, or React.use())