-
Notifications
You must be signed in to change notification settings - Fork 28.5k
useEffect
not working in root loading.tsx
on initial loading
#41972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@lukemorales i have the same issue apart from my data isnt being fetched in my case. useEffect not getting called in a client side component. |
useEffect
not working in loading.tsx
useEffect
not working in root loading.tsx
useEffect
not working in root loading.tsx
useEffect
not working in root loading.tsx
on initial loading
Just changed the title because I was able to see state updates happening on nested routes, and the root loading also updating if my App entry point was a nested route then navigating back to the |
useEffect is also not working in a client component that has a server component as child, imported from a server component. |
Similarly, I was just playing around with |
Might have found some related content. After reading that post, it seems to suggest that there is not enough JS loaded to client render/hydrate the app and this is a result of the page still streaming in with that runtime. However, we can clearly see the So I guess the follow up is either can this behavior be avoided like If there is a way to avoid it, then let’s implement it so we can seamlessly use React features when the loader is marked “use client”. It seems reasonable to expect it to run SSR and rehydrate on any suspension. If we can’t avoid it, maybe we need a new API to signal developers that there is at first a render that cannot fully take advantage of the client and then subsequent loads can leverage client only. This might be similar to “error.tsx” vs “global-error.tsx” to create a server only loader. Or simply prohibit client loaders (which seems aggressively opinionated). Both options seems bad from either an implementation side or a DX side. |
Given the radio silence from Vercel, this ugly hack is working for me. For ONLY the loading.tsx file, use
|
It happens in Next v14 also |
Hey folks, sorry for the delay here. In the case of For something like implementing a loading spinner, we suggest using CSS animations that work off thread rather than relying on JS. In most cases, by the time the user downloaded the necessary JS to power the loading state (which would have been frozen up until hydration anyway), the loading state should have finished. |
Thanks for the response. This probably needs some sort of documentation then if the page is never going to be hydrated and won't run effects. Currently, it just says we can slap |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Uh oh!
There was an error while loading. Please reload this page.
Verify canary release
Provide environment information
What browser are you using? (if relevant)
Arc Browser
How are you deploying your application? (if relevant)
No response
Describe the Bug
loading.tsx
does not throw any errors if made a Client Component with'use client'
declarative, however,useEffect
does not run on Loading components.Expected Behavior
useEffect
is execute.Link to reproduction
https://stackblitz.com/edit/vercel-next-js-duighx?file=app/loading.tsx
To Reproduce
Create a loading file in
/app
directory and use the following code:The text was updated successfully, but these errors were encountered: