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.

Configure delay for 'onRouteUpdateDelayed' hook ?

See original GitHub issue

Summary

Is it possible to configure the delay for ‘onRouteUpdateDelayed’ hook ?

Relevant information

Documentation link: https://www.gatsbyjs.org/docs/browser-apis/#onRouteUpdateDelayed

For my page I implement a loading indicator. Therefore I would like to configure the default delay for the ‘onRouteUpdateDelayed’ hook. Currently I use it inside the gatsby-browser.js like so:

exports.onRouteUpdateDelayed = () => {
  window.___emitter.emit('onRouteUpdateDelayed');
};

The default delay is 1s but i would like to show the spinner earlier like after 500ms or so…

Gatsby info

  System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
    Shell: Unknown
  Binaries:
    Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
    npm: 6.13.7 - ~/.nvm/versions/node/v12.13.0/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 81.0.4044.129
    Firefox: 75.0
    Safari: 13.1
  npmPackages:
    gatsby: ^2.20.12 => 2.20.15 
    gatsby-image: ^2.3.1 => 2.3.1 
    gatsby-plugin-layout: ^1.2.2 => 1.2.2 
    gatsby-plugin-manifest: ^2.3.3 => 2.3.3 
    gatsby-plugin-offline: ^3.1.2 => 3.1.2 
    gatsby-plugin-react-helmet: ^3.2.1 => 3.2.1 
    gatsby-plugin-react-svg: 3.0.0 => 3.0.0 
    gatsby-plugin-sass: ^2.2.1 => 2.2.1 
    gatsby-plugin-sharp: ^2.5.3 => 2.5.3 
    gatsby-source-filesystem: 2.3.0 => 2.3.0 
    gatsby-source-multi-api: 1.0.3 => 1.0.3 
    gatsby-transformer-json: 2.4.0 => 2.4.0 
    gatsby-transformer-sharp: ^2.4.3 => 2.4.3 

File contents (if changed)

gatsby-config.js: N/A package.json: N/A gatsby-node.js: N/A gatsby-browser.js:

exports.onRouteUpdateDelayed = () => {
  window.___emitter.emit('onRouteUpdateDelayed');
};

exports.onRouteUpdate = () => {
  window.___emitter.emit('onRouteUpdate');
};

gatsby-ssr.js: N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
gethinwebstercommented, Jul 30, 2021

Suggest reopening this as I’ve also come across this problem - I want to be able to adjust this delay, and the suggestion of using onPreRouteUpdate is incorrect, as this hook gets called too late (after the new page is loaded, but before it’s rendered)

2reactions
anasbouzidcommented, Sep 27, 2020

The new api that you proposed onRouteUpdateStart already exists with the name onPreRouteUpdate. So, people wanting to bail out of the 1s delay can just use a combination of onPreRouteUpdate and onRouteUpdate.

@jzabala I don’t think onPreRouteUpdate is the correct API. I’ve done some testing on https://xzvto-8000.sse.codesandbox.io/page-2/ (source) and on a simulated slow network, the onRouteUpdateDelayed event is fired before onPreRouteUpdate (make sure you click a link before it’s prefetched)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange behavior of React hooks: delayed data update
The state update is asynchronous so if you are using Hooks you can use useEffect to be notified after an update. Here is...
Read more >
Gatsby Browser APIs
Documentation about leveraging standard browser APIs within Gatsby.
Read more >
Eight Time-Saving Gatsby Plugins - Better Programming
Just add the plugin to the plugins array in your gatsby-config.js ... Delays sending pageview hits on route update (in milliseconds)
Read more >
Caching with service worker and Workbox | Node.js Developer
After successful installation, the updated service worker delays ... It requires the initialization of the DataSource configuration.
Read more >
Fix delayed state update in React. Receiving Previous value ...
useState() Hook in class and function components, respectively. ... but React may delay the changes, updating several components in a single ...
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