question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Show loading indicator while getInitialProps() is running

See original GitHub issue

The way I understand the loadingComponent prop, it is only shown if the target screen is configured to return null. Is is possible to show the loading indicator while getInitialProps of the loading screen is executing? This would allow to use the indicator without specifically handling serverside and clientside handling.

I would assume that it is possible by hooking into next.js router events. However, I think that the problem might be with triggering the transition before the new component exists.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
EyMaddiscommented, Jul 29, 2019

I was basically aiming for something else while investigating this: Hiding my loading times.

Currently the flow is like this with a simple fade animation between screens which takes 500ms.

  • user presses on button
  • getInitialProps() is loading the content for the next page, this might take 500ms
  • next page renders (lets say that this is instantly)
  • fade out begins +250ms
  • fade in begins +250ms

The user sees the page after 1 second.

This is what I was aiming for:

  • user presses on button
  • fade out begins AND getInitialProps() is loading the content for the next page, this might take up 500ms, but at least the 250ms of the transition
  • next page renders (lets say that this is instantly)
  • fade in begins +250

If getInitialProps resolves within 250ms, the user sees the page after 0.5 seconds instead of 1!

0reactions
EyMaddiscommented, Nov 7, 2019

With the “withLoading” example I actually just mean exactly that functionality. I added a global loading indicator to the page, a little bar at the top of the page that grows in a known interval. I did not adapt the transitions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a loading indicator between <Link /> navigations #238
I just peek through the code and it seems to do two async ops mainly: Fetch the code; Fetch data. So, we need...
Read more >
getInitialProps - Data Fetching - Next.js
For the initial page load, getInitialProps will run on the server only. getInitialProps will then run on the client when navigating to a...
Read more >
nextjs getServerSideProps show loading - Stack Overflow
json is being loaded by fetchNextData. I would like to show a loading spinner when I move from one route to another using...
Read more >
Refreshing Server-Side Props - Next.js - Josh W Comeau
When the server returns fresh data, the hook will fire, and our loading state will terminate. And it protects us against "incidental" renders, ......
Read more >
Data fetching in React and Next.js with useSWR to impress ...
Stale-While-Revalidate is the concept to show stale, cached data, ... For the initial page load, getInitialProps will run on the server only ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found