Open Princezhm opened 1 year ago
I think the loading behavior is a hard problem to solve Since nextjs uses streaming to show loading before the page has finished loading even JavaScript code. Because of that your loading page cannot be interactive because nextjs has to load the JS first, hydrate your page then run the client code.
It cannot work when your user load the page first (full reload of the browser), but i think it could work between page transitions, since the JS has already been loaded. But i could also be wrong about page transitions and the loading page cannot be interactive 🤷🏾♂️.
@reza-ebrahimi are you sure you are on the right issue ?
Based on my understanding this is related to React v18.0 new
StrictMode
modes.
dont know either how this is related but thanks for sharing the side effect of strict mode... i wondered why i have all these double calls in my code ;-)
Any progress on this? i am having the same issue, i cannot run hooks in loading js, it works when i navigate to tother pages, but not when i first load the page
I think it makes sense for hooks not to work, as the JavaScript needed to run the hook is still "loading", that's why the loading page exists
The docs indicate that this should work
https://nextjs.org/docs/app/api-reference/file-conventions/loading
By default, this file is a Server Component - but can also be used as a Client Component through the "use client" directive.
But I am also having this problem -- when loading.js
sets use client
, its hooks and its child component hooks aren't called
Likewise, I'm trying to create an animated loading spinner using react-spring, and failing on the loading.tsx page as no useEffect seems to be called. The root svg element is loaded, however, no updates occur to the documents state.
Verify canary release
Provide environment information
brand new clean install of Next13
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
local
To Reproduce
experimental: { appDir: true },
to thenext.config.js
filelayout.js
page.js
andloading.js
(the last one is the issue)Layout Code:
page code:
loading code:
Describe the Bug
I found this bug while creating a loading screen for my application, I was trying to use
anime.js
in the loading screen and then I noticed none of the hooks I defined where being called.despite that I was able to call my function
animateEverything
outside of everything, as I stated on the steps and it started to work (actually the animation was starting) but when I was trying to build I got an error like this:also another thing that I noticed was that if I put some functions with more logs in the code, they were appearing on the terminal instead of the chrome console. for example
loading code:
other things that I was testing is leaving the
loading.js
file as a server component and create another with the loader, then call it fromloading.js
but same behaviour.Expected Behavior
it should behave as a client component and use correctly the hooks without problems.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
Vercel