Top level await
Answered
Bohemian Shepherd posted this in #help-forum
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
4 Replies
@Bohemian Shepherd 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
yea it works, but only in server components, not in client components
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())@Bohemian Shepherd solved? Please mark solution[:](https://cdn.discordapp.com/attachments/1043615796787683408/1117191182133501962/image.png?ex=679e865e&is=679d34de&hm=362965c2242a1544fbdf6499d7d0d5dd21a9ec23cd77f9d637e4d589fc016f36&)