-
Notifications
You must be signed in to change notification settings - Fork 38
Feature Request: Show loading indicator while getInitialProps() is running #36
Comments
Router events appear to be how next.js recommends you do it. |
Can you clarify what you mean by "it is only shown if the target screen is configured to return null"? As always, a concrete example (https://codesandbox.io is great for this) is helpful to illustrate exactly what you're talking about. |
I meant just the example here: In order for the loading indicator to work, the page has to look like this: render() {
if (!this.state.loaded) return null // no loading indicator without this.
return <div>Hello, world!</div>
} |
Ah, I see what you mean. This is by design - if your page can render immediately, you shouldn't need a loading indicator. Do you have a specific use case where you want both the page and a loading indicator to render at the same time? |
I just assumed that the loading indicator would show like the next page is getting loaded (specifically while next.js resolves the I solved this in my project by adapting: For me it was a clash of assumptions. |
Ah! Apologies - I didn't use this package with |
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.
The user sees the page after 1 second. This is what I was aiming for:
If getInitialProps resolves within 250ms, the user sees the page after 0.5 seconds instead of 1! |
I am also struggling with this exact issue. The Main reason we use NextJS is due to I have followed along with the |
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. |
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.
The text was updated successfully, but these errors were encountered: