Skip to content
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

gatsby-link determine when loading is complete #2906

Closed
baseten opened this issue Nov 13, 2017 · 5 comments · May be fixed by tejzpr/gatsby#61
Closed

gatsby-link determine when loading is complete #2906

baseten opened this issue Nov 13, 2017 · 5 comments · May be fixed by tejzpr/gatsby#61

Comments

@baseten
Copy link

baseten commented Nov 13, 2017

Does gatsby-link provide any sort of event or callback that I can use to determine when the load for the code chunks for the incoming page has completed? Gatsby seems to use a global ___loader instance to manage this, but this doesn't seem to have any documentation. Can I use onPostLoadPageResources somehow?

@KyleAMathews
Copy link
Contributor

Not right now.

What is your use case for wanting to know when loading is complete?

@baseten
Copy link
Author

baseten commented Nov 13, 2017

I've updated to the latest gatsby-link version where data is preloaded if the link is in the viewport so this is less of an issue now. Before after clicking a link there was a significant wait before displaying the page and I wanted to show a loader. This would still be a useful thing to do and I have implemented at the moment as follows in my onInitialClientRender in gatsby-browser:

window.___emitter.on( 'onPostLoadPageResources', e => {
    // dispatch redux action with e.page
} );
@KyleAMathews
Copy link
Contributor

Ah interesting — yeah exposing the emitter could be interesting too at some point.

I like to be cautious though about making APIs public as they're fairly set in stone at that point.

You might want to look at the source of https://www.gatsbyjs.org/packages/gatsby-plugin-nprogress/ as well.

Good to hear that avoiding preloading links if not in the viewport made a noticeable improvement!

@baseten
Copy link
Author

baseten commented Nov 13, 2017

Ah, good to know I was on the right track! I'll use the onDelayedLoadPageResources event too.

Makes sense regarding exposing APIs as well.

@Chuloo
Copy link
Contributor

Chuloo commented Aug 29, 2018

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues as many of them have already been resolved with the latest updates or explained in a previous issue.

Feel free to open a new one if you still experience this problem or a similar one! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants