NextJS 14 - cannot get loading.tsx to render as page.tsx loads data
Unanswered
Sloth bear posted this in #help-forum
Sloth bearOP
My stackoverflow: https://stackoverflow.com/questions/78265073/nextjs-14-loading-tsx-component-not-rendering-loading-animation-as-a-get-reque
Screen recording: https://www.youtube.com/watch?v=K5nphIY7A5k
Would appreciate any help on this, the documentation and all the tutorials I've seen online are super straight forward, so curious why I'm not seeing the Loading animation 😢
Screen recording: https://www.youtube.com/watch?v=K5nphIY7A5k
Would appreciate any help on this, the documentation and all the tutorials I've seen online are super straight forward, so curious why I'm not seeing the Loading animation 😢
18 Replies
@Sloth bear My stackoverflow: https://stackoverflow.com/questions/78265073/nextjs-14-loading-tsx-component-not-rendering-loading-animation-as-a-get-reque
Screen recording: https://www.youtube.com/watch?v=K5nphIY7A5k
Would appreciate any help on this, the documentation and all the tutorials I've seen online are super straight forward, so curious why I'm not seeing the Loading animation 😢
because you are fetching on client component
all you need is turn page.tsx to server component and fetch on server side, you don't need to import the
loading.tsx and wrap the children with Suspense which has already handled by next@Sloth bear My stackoverflow: https://stackoverflow.com/questions/78265073/nextjs-14-loading-tsx-component-not-rendering-loading-animation-as-a-get-reque
Screen recording: https://www.youtube.com/watch?v=K5nphIY7A5k
Would appreciate any help on this, the documentation and all the tutorials I've seen online are super straight forward, so curious why I'm not seeing the Loading animation 😢
I think you are fetching the images in
useEffect and that doesn't trigger the suspense boundaryif you really want to fetch data in client component, use the react's
useit also triggers the suspense boundary
@@ts-ignore if you really want to fetch data in client component, use the react's `use`
use cause infinity fetch for me last time I tried@Ray `use` cause infinity fetch for me last time I tried
I tried it day before yesterday and it was working fine
@@ts-ignore I tried it day before yesterday and it was working fine
it is still causing infinity fetch for me
@@ts-ignore I think you are fetching the images in `useEffect` and that doesn't trigger the suspense boundary
Sloth bearOP
Oh thanks I did not know this, so it has to be a server component for loading to work? I can't use useState or useEffect in server components.
My thoughts are make a fetch, then you need to save the data into Redux, then display data via useSelector
@Sloth bear My thoughts are make a fetch, then you need to save the data into Redux, then display data via useSelector
then loading.tsx won't trigger if you fetch in useEffect, I'd suggest you to fetch it in server component and pass down as prop or the react's
use can be called conditionally and inside other functions so you can also give that a shotSloth bearOP
Ok so fetch within the page.tsx, then pass it into my Client component which then saves it into Redux?
but give the
use a shot if it workscan be helpful
Sloth bearOP
This issue has been solved, thanks!